Imported Upstream version 4.4
[platform/upstream/make.git] / src / output.h
1 /* Output to stdout / stderr for GNU make
2 Copyright (C) 2013-2022 Free Software Foundation, Inc.
3 This file is part of GNU Make.
4
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
8 version.
9
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.
13
14 You should have received a copy of the GNU General Public License along with
15 this program.  If not, see <https://www.gnu.org/licenses/>.  */
16
17 struct output
18   {
19     int out;
20     int err;
21     unsigned int syncout:1;     /* True if we want to synchronize output.  */
22  };
23
24 extern struct output *output_context;
25 extern unsigned int stdio_traced;
26
27 #define FD_STDIN  (fileno (stdin))
28 #define FD_STDOUT (fileno (stdout))
29 #define FD_STDERR (fileno (stderr))
30
31 #define OUTPUT_SET(_new)    do{ output_context = (_new)->syncout ? (_new) : NULL; }while(0)
32 #define OUTPUT_UNSET()      do{ output_context = NULL; }while(0)
33
34 #define OUTPUT_TRACED()     do{ stdio_traced = 1; }while(0)
35 #define OUTPUT_IS_TRACED()  (!!stdio_traced)
36
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);
40
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);
45
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);
49
50 /* Show a message on stdout or stderr.  Will start the output if needed.  */
51 void outputs (int is_err, const char *msg);
52
53 #if defined(NO_OUTPUT_SYNC)
54 # define output_dump(_o) (void)(0)
55 #else
56 /* Dump any child output content to stdout, and reset it.  */
57 void output_dump (struct output *out);
58 #endif