1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: pipe.c 761 2007-10-23 22:35:18Z hubert@u.washington.edu $";
5 * ========================================================================
6 * Copyright 2013-2017 Eduardo Chappa
7 * Copyright 2006 University of Washington
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * ========================================================================
18 #include "../pith/headers.h"
19 #include "../pith/pipe.h"
20 #include "../pith/status.h"
23 /* Internal prototypes */
28 * pipe_* functions introduced so out.f, in.f don't need to be used
29 * by whatever's setting up the pipe.
30 * Should be similar on unix and windows, but since we're faking piping
31 * in windows, closing the write pipe would signify that the child
32 * process can start running. This makes it possible for PIPE_WRITE
33 * and PIPE_READ flags to be simultaneously set across all platforms.
34 * Unix piping should eventually have NON_BLOCKING_IO stuff rolled up
39 pipe_putc(int c
, PIPE_S
*syspipe
)
41 if(!syspipe
|| !syspipe
->out
.f
)
44 return(fputc(c
, syspipe
->out
.f
));
48 pipe_puts(char *str
, PIPE_S
*syspipe
)
50 if(!syspipe
|| !syspipe
->out
.f
)
53 return(fputs(str
, syspipe
->out
.f
));
57 pipe_gets(char *str
, int size
, PIPE_S
*syspipe
)
59 if(!syspipe
|| !syspipe
->in
.f
)
62 return(fgets(str
, size
, syspipe
->in
.f
));
66 pipe_readc(unsigned char *c
, PIPE_S
*syspipe
)
70 if(!syspipe
|| !syspipe
->in
.f
)
75 clearerr(syspipe
->in
.f
);
76 rv
= fread(c
, sizeof(unsigned char), (size_t)1, syspipe
->in
.f
);
77 } while(!rv
&& ferror(syspipe
->in
.f
) && errno
== EINTR
);
83 pipe_writec(int c
, PIPE_S
*syspipe
)
85 unsigned char ch
= (unsigned char)c
;
88 if(!syspipe
|| !syspipe
->out
.f
)
92 rv
= fwrite(&ch
, sizeof(unsigned char), (size_t)1, syspipe
->out
.f
);
93 while(!rv
&& ferror(syspipe
->out
.f
) && errno
== EINTR
);
100 pipe_report_error(char *errormsg
)
102 q_status_message(SM_ORDER
, 3, 3, errormsg
);