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 2006 University of Washington
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * ========================================================================
17 #include "../pith/headers.h"
18 #include "../pith/pipe.h"
19 #include "../pith/status.h"
22 /* Internal prototypes */
27 * pipe_* functions introduced so out.f, in.f don't need to be used
28 * by whatever's setting up the pipe.
29 * Should be similar on unix and windows, but since we're faking piping
30 * in windows, closing the write pipe would signify that the child
31 * process can start running. This makes it possible for PIPE_WRITE
32 * and PIPE_READ flags to be simultaneously set across all platforms.
33 * Unix piping should eventually have NON_BLOCKING_IO stuff rolled up
38 pipe_putc(int c
, PIPE_S
*syspipe
)
40 if(!syspipe
|| !syspipe
->out
.f
)
43 return(fputc(c
, syspipe
->out
.f
));
47 pipe_puts(char *str
, PIPE_S
*syspipe
)
49 if(!syspipe
|| !syspipe
->out
.f
)
52 return(fputs(str
, syspipe
->out
.f
));
56 pipe_gets(char *str
, int size
, PIPE_S
*syspipe
)
58 if(!syspipe
|| !syspipe
->in
.f
)
61 return(fgets(str
, size
, syspipe
->in
.f
));
65 pipe_readc(unsigned char *c
, PIPE_S
*syspipe
)
69 if(!syspipe
|| !syspipe
->in
.f
)
74 clearerr(syspipe
->in
.f
);
75 rv
= fread(c
, sizeof(unsigned char), (size_t)1, syspipe
->in
.f
);
76 } while(!rv
&& ferror(syspipe
->in
.f
) && errno
== EINTR
);
82 pipe_writec(int c
, PIPE_S
*syspipe
)
84 unsigned char ch
= (unsigned char)c
;
87 if(!syspipe
|| !syspipe
->out
.f
)
91 rv
= fwrite(&ch
, sizeof(unsigned char), (size_t)1, syspipe
->out
.f
);
92 while(!rv
&& ferror(syspipe
->out
.f
) && errno
== EINTR
);
99 pipe_report_error(char *errormsg
)
101 q_status_message(SM_ORDER
, 3, 3, errormsg
);