2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 #include "../pith/headers.h"
16 #include "../pith/pipe.h"
17 #include "../pith/status.h"
20 /* Internal prototypes */
25 * pipe_* functions introduced so out.f, in.f don't need to be used
26 * by whatever's setting up the pipe.
27 * Should be similar on unix and windows, but since we're faking piping
28 * in windows, closing the write pipe would signify that the child
29 * process can start running. This makes it possible for PIPE_WRITE
30 * and PIPE_READ flags to be simultaneously set across all platforms.
31 * Unix piping should eventually have NON_BLOCKING_IO stuff rolled up
36 pipe_putc(int c
, PIPE_S
*syspipe
)
38 if(!syspipe
|| !syspipe
->out
.f
)
41 return(fputc(c
, syspipe
->out
.f
));
45 pipe_puts(char *str
, PIPE_S
*syspipe
)
47 if(!syspipe
|| !syspipe
->out
.f
)
50 return(fputs(str
, syspipe
->out
.f
));
54 pipe_gets(char *str
, int size
, PIPE_S
*syspipe
)
56 if(!syspipe
|| !syspipe
->in
.f
)
59 return(fgets(str
, size
, syspipe
->in
.f
));
63 pipe_readc(unsigned char *c
, PIPE_S
*syspipe
)
67 if(!syspipe
|| !syspipe
->in
.f
)
72 clearerr(syspipe
->in
.f
);
73 rv
= fread(c
, sizeof(unsigned char), (size_t)1, syspipe
->in
.f
);
74 } while(!rv
&& ferror(syspipe
->in
.f
) && errno
== EINTR
);
80 pipe_writec(int c
, PIPE_S
*syspipe
)
82 unsigned char ch
= (unsigned char)c
;
85 if(!syspipe
|| !syspipe
->out
.f
)
89 rv
= fwrite(&ch
, sizeof(unsigned char), (size_t)1, syspipe
->out
.f
);
90 while(!rv
&& ferror(syspipe
->out
.f
) && errno
== EINTR
);
97 pipe_report_error(char *errormsg
)
99 q_status_message(SM_ORDER
, 3, 3, errormsg
);