1 | /* Output to stdout / stderr for GNU make
|
---|
2 | Copyright (C) 2013-2016 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 | #ifdef CONFIG_WITH_OUTPUT_IN_MEMORY
|
---|
18 | /* Output run. */
|
---|
19 | struct output_run
|
---|
20 | {
|
---|
21 | unsigned int seqno; /* For interleaving out/err output. */
|
---|
22 | unsigned int len; /* The length of the output. */
|
---|
23 | struct output_run *next; /* Pointer to the next run. */
|
---|
24 | };
|
---|
25 |
|
---|
26 | /* Output segment. */
|
---|
27 | struct output_segment
|
---|
28 | {
|
---|
29 | struct output_segment *next;
|
---|
30 | size_t size; /* Segment size, everything included. */
|
---|
31 | struct output_run runs[1];
|
---|
32 | };
|
---|
33 |
|
---|
34 | /* Output memory buffer. */
|
---|
35 | struct output_membuf
|
---|
36 | {
|
---|
37 | struct output_run *head_run;
|
---|
38 | struct output_run *tail_run; /* Always in tail_seg. */
|
---|
39 | struct output_segment *head_seg;
|
---|
40 | struct output_segment *tail_seg;
|
---|
41 | size_t left; /* Number of bytes that can be appended to
|
---|
42 | the tail_run. */
|
---|
43 | size_t total; /* Total segment allocation size. */
|
---|
44 | };
|
---|
45 | #endif /* CONFIG_WITH_OUTPUT_IN_MEMORY */
|
---|
46 |
|
---|
47 | struct output
|
---|
48 | {
|
---|
49 | #ifdef CONFIG_WITH_OUTPUT_IN_MEMORY
|
---|
50 | struct output_membuf out;
|
---|
51 | struct output_membuf err;
|
---|
52 | unsigned int seqno; /* The current run sequence number. */
|
---|
53 | #else
|
---|
54 | int out;
|
---|
55 | int err;
|
---|
56 | #endif
|
---|
57 | unsigned int syncout:1; /* True if we want to synchronize output. */
|
---|
58 | };
|
---|
59 |
|
---|
60 | extern struct output *output_context;
|
---|
61 | extern unsigned int stdio_traced;
|
---|
62 |
|
---|
63 | #define OUTPUT_SET(_new) do{ output_context = (_new)->syncout ? (_new) : NULL; }while(0)
|
---|
64 | #define OUTPUT_UNSET() do{ output_context = NULL; }while(0)
|
---|
65 |
|
---|
66 | #define OUTPUT_TRACED() do{ stdio_traced = 1; }while(0)
|
---|
67 | #define OUTPUT_IS_TRACED() (!!stdio_traced)
|
---|
68 |
|
---|
69 | FILE *output_tmpfile (char **, const char *);
|
---|
70 |
|
---|
71 | /* Initialize and close a child output structure: if NULL do this program's
|
---|
72 | output (this should only be done once). */
|
---|
73 | void output_init (struct output *out);
|
---|
74 | void output_close (struct output *out);
|
---|
75 |
|
---|
76 | /* In situations where output may be about to be displayed but we're not
|
---|
77 | sure if we've set it up yet, call this. */
|
---|
78 | void output_start (void);
|
---|
79 |
|
---|
80 | /* Show a message on stdout or stderr. Will start the output if needed. */
|
---|
81 | void outputs (int is_err, const char *msg);
|
---|
82 | #ifdef CONFIG_WITH_OUTPUT_IN_MEMORY
|
---|
83 | void output_write_bin (struct output *out, int is_err, const char *src, size_t len);
|
---|
84 | void output_write_text (struct output *out, int is_err, const char *src, size_t len);
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | #ifndef NO_OUTPUT_SYNC
|
---|
88 | int output_tmpfd (void);
|
---|
89 | /* Dump any child output content to stdout, and reset it. */
|
---|
90 | void output_dump (struct output *out);
|
---|
91 | #endif
|
---|