temporary commit while I update master
[alpine.git] / pith / pipe.c
blobe44a47f19eae13608119682f0e935e9485682475
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: pipe.c 761 2007-10-23 22:35:18Z hubert@u.washington.edu $";
3 #endif
4 /*
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
35 * into it.
38 int
39 pipe_putc(int c, PIPE_S *syspipe)
41 if(!syspipe || !syspipe->out.f)
42 return -1;
44 return(fputc(c, syspipe->out.f));
47 int
48 pipe_puts(char *str, PIPE_S *syspipe)
50 if(!syspipe || !syspipe->out.f)
51 return -1;
53 return(fputs(str, syspipe->out.f));
56 char *
57 pipe_gets(char *str, int size, PIPE_S *syspipe)
59 if(!syspipe || !syspipe->in.f)
60 return NULL;
62 return(fgets(str, size, syspipe->in.f));
65 int
66 pipe_readc(unsigned char *c, PIPE_S *syspipe)
68 int rv = 0;
70 if(!syspipe || !syspipe->in.f)
71 return -1;
73 do {
74 errno = 0;
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);
79 return(rv);
82 int
83 pipe_writec(int c, PIPE_S *syspipe)
85 unsigned char ch = (unsigned char)c;
86 int rv = 0;
88 if(!syspipe || !syspipe->out.f)
89 return -1;
92 rv = fwrite(&ch, sizeof(unsigned char), (size_t)1, syspipe->out.f);
93 while(!rv && ferror(syspipe->out.f) && errno == EINTR);
95 return(rv);
99 void
100 pipe_report_error(char *errormsg)
102 q_status_message(SM_ORDER, 3, 3, errormsg);