1 /* Output to stdout / stderr for GNU make
2 Copyright (C) 2013-2020 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
21 unsigned int syncout:1; /* True if we want to synchronize output. */
24 extern struct output *output_context;
25 extern unsigned int stdio_traced;
27 #define FD_STDIN (fileno (stdin))
28 #define FD_STDOUT (fileno (stdout))
29 #define FD_STDERR (fileno (stderr))
31 #define OUTPUT_SET(_new) do{ output_context = (_new)->syncout ? (_new) : NULL; }while(0)
32 #define OUTPUT_UNSET() do{ output_context = NULL; }while(0)
34 #define OUTPUT_TRACED() do{ stdio_traced = 1; }while(0)
35 #define OUTPUT_IS_TRACED() (!!stdio_traced)
37 /* Write a buffer directly to the given file descriptor.
38 This handles errors etc. */
39 int output_write (int fd, const void *buffer, size_t len);
41 /* Initialize and close a child output structure: if NULL do this program's
42 output (this should only be done once). */
43 void output_init (struct output *out);
44 void output_close (struct output *out);
46 /* In situations where output may be about to be displayed but we're not
47 sure if we've set it up yet, call this. */
48 void output_start (void);
50 /* Show a message on stdout or stderr. Will start the output if needed. */
51 void outputs (int is_err, const char *msg);
53 #if defined(HAVE_FCNTL_H)
55 #elif defined(HAVE_SYS_FILE_H)
56 # include <sys/file.h>
60 # define RECORD_SYNC_MUTEX(m) \
62 _("-O[TYPE] (--output-sync[=TYPE]) is not configured for this build."));
64 int output_tmpfd (void);
65 /* Dump any child output content to stdout, and reset it. */
66 void output_dump (struct output *out);
69 /* For emulations in w32/compat/posixfcn.c. */
72 /* Implementation note: None of the values of l_type below can be zero
73 -- they are compared with a static instance of the struct, so zero
74 means unknown/invalid, see w32/compat/posixfcn.c. */
87 /* This type is actually a HANDLE, but we want to avoid including
88 windows.h as much as possible. */
89 typedef intptr_t sync_handle_t;
91 /* Public functions emulated/provided in posixfcn.c. */
92 int fcntl (intptr_t fd, int cmd, ...);
93 intptr_t create_mutex (void);
94 int same_stream (FILE *f1, FILE *f2);
96 # define RECORD_SYNC_MUTEX(m) record_sync_mutex(m)
97 void record_sync_mutex (const char *str);
98 void prepare_mutex_handle_string (intptr_t hdl);
99 # else /* !WINDOWS32 */
101 typedef int sync_handle_t; /* file descriptor */
103 # define RECORD_SYNC_MUTEX(m) (void)(m)
106 #endif /* !NO_OUTPUT_SYNC */