source: trunk/src/kmk/output.h@ 3190

Last change on this file since 3190 was 3190, checked in by bird, 7 years ago

kmk/output: Basic memory buffered output working.

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1/* Output to stdout / stderr for GNU make
2Copyright (C) 2013-2016 Free Software Foundation, Inc.
3This file is part of GNU Make.
4
5GNU Make is free software; you can redistribute it and/or modify it under the
6terms of the GNU General Public License as published by the Free Software
7Foundation; either version 3 of the License, or (at your option) any later
8version.
9
10GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifdef CONFIG_WITH_OUTPUT_IN_MEMORY
18/* Output run. */
19struct 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. */
27struct 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. */
35struct 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
47struct 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
60extern struct output *output_context;
61extern 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
69FILE *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). */
73void output_init (struct output *out);
74void 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. */
78void output_start (void);
79
80/* Show a message on stdout or stderr. Will start the output if needed. */
81void outputs (int is_err, const char *msg);
82#ifdef CONFIG_WITH_OUTPUT_IN_MEMORY
83void output_write_bin (struct output *out, int is_err, const char *src, size_t len);
84void output_write_text (struct output *out, int is_err, const char *src, size_t len);
85#endif
86
87#ifndef NO_OUTPUT_SYNC
88int output_tmpfd (void);
89/* Dump any child output content to stdout, and reset it. */
90void output_dump (struct output *out);
91#endif
Note: See TracBrowser for help on using the repository browser.