[Tizen_6_build] Fixed 32-bit arm build with gcc 9
[platform/upstream/boost-jam.git] / output.c
1 /*
2     Copyright 2007 Rene Rivera
3     Distributed under the Boost Software License, Version 1.0.
4     (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
5 */
6
7 #include "jam.h"
8 #include "output.h"
9 #include "newstr.h"
10 #include <stdio.h>
11
12 #define bjam_out (stdout)
13 #define bjam_err (stderr)
14
15 static void out_
16 (
17     char const * data,
18     FILE       * io
19 )
20 {
21     while ( *data )
22     {
23         size_t len = strcspn(data,"\r");
24         data += fwrite(data,1,len,io);
25         if ( *data == '\r' ) ++data;
26     }
27 }
28
29
30 void out_action
31 (
32     char const * action,
33     char const * target,
34     char const * command,
35     char const * out_data,
36     char const * err_data,
37     int          exit_reason
38 )
39 {
40     /* Print out the action+target line, if the action is quite the action
41      * should be null.
42      */
43     if ( action )
44     {
45         fprintf( bjam_out, "%s %s\n", action, target );
46     }
47
48     /* Print out the command executed if given -d+2. */
49     if ( DEBUG_EXEC )
50     {
51         fputs( command, bjam_out );
52         fputc( '\n', bjam_out );
53     }
54
55     /* Print out the command executed to the command stream. */
56     if ( globs.cmdout )
57     {
58         fputs( command, globs.cmdout );
59     }
60
61     switch ( exit_reason )
62     {
63         case EXIT_OK:
64             break;
65         case EXIT_FAIL:
66             break;
67         case EXIT_TIMEOUT:
68         {
69             /* Process expired, make user aware with explicit message. */
70             if ( action )
71             {
72                 /* But only output for non-quietly actions. */
73                 fprintf( bjam_out, "%ld second time limit exceeded\n", globs.timeout );
74             }
75             break;
76         }
77         default:
78           break;
79     }
80
81     /* Print out the command output, if requested, or if the program failed. */
82     if ( action || exit_reason != EXIT_OK)
83     {
84         /* But only output for non-quietly actions. */
85         if ( ( 0 != out_data ) &&
86            ( ( globs.pipe_action & 1 /* STDOUT_FILENO */ ) ||
87              ( globs.pipe_action == 0 ) ) )
88         {
89             out_( out_data, bjam_out );
90         }
91         if ( ( 0 != err_data ) &&
92             ( globs.pipe_action & 2 /* STDERR_FILENO */ ) )
93         {
94             out_( err_data, bjam_err );
95         }
96     }
97
98     fflush( bjam_out );
99     fflush( bjam_err );
100     fflush( globs.cmdout );
101 }
102
103
104 char * outf_int( int value )
105 {
106     char buffer[50];
107     sprintf( buffer, "%i", value );
108     return newstr( buffer );
109 }
110
111
112 char * outf_double( double value )
113 {
114     char buffer[50];
115     sprintf( buffer, "%f", value );
116     return newstr( buffer );
117 }
118
119
120 char * outf_time( time_t value )
121 {
122     char buffer[50];
123     strftime( buffer, 49, "%Y-%m-%d %H:%M:%SZ", gmtime( &value ) );
124     return newstr( buffer );
125 }