Change make license
[platform/upstream/make.git] / src / output.h
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.
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 <http://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(HAVE_FCNTL_H)
54 # include <fcntl.h>
55 #elif defined(HAVE_SYS_FILE_H)
56 # include <sys/file.h>
57 #endif
58
59 #ifdef NO_OUTPUT_SYNC
60 # define RECORD_SYNC_MUTEX(m) \
61     O (error, NILF,                                                    \
62        _("-O[TYPE] (--output-sync[=TYPE]) is not configured for this build."));
63 #else
64 int output_tmpfd (void);
65 /* Dump any child output content to stdout, and reset it.  */
66 void output_dump (struct output *out);
67
68 # ifdef WINDOWS32
69 /* For emulations in w32/compat/posixfcn.c.  */
70 #  define F_GETFD 1
71 #  define F_SETLKW 2
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. */
75 #  define F_WRLCK 1
76 #  define F_UNLCK 2
77
78 struct flock
79   {
80     short l_type;
81     short l_whence;
82     off_t l_start;
83     off_t l_len;
84     pid_t l_pid;
85   };
86
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;
90
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);
95
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 */
100
101 typedef int sync_handle_t;      /* file descriptor */
102
103 #  define RECORD_SYNC_MUTEX(m) (void)(m)
104
105 # endif
106 #endif  /* !NO_OUTPUT_SYNC */