* Create help for explaining how encrypted password file support
[alpine.git] / pith / pipe.c
blob35549eefb647e1eafd5c76579c300c12b7349fbd
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 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
34 * into it.
37 int
38 pipe_putc(int c, PIPE_S *syspipe)
40 if(!syspipe || !syspipe->out.f)
41 return -1;
43 return(fputc(c, syspipe->out.f));
46 int
47 pipe_puts(char *str, PIPE_S *syspipe)
49 if(!syspipe || !syspipe->out.f)
50 return -1;
52 return(fputs(str, syspipe->out.f));
55 char *
56 pipe_gets(char *str, int size, PIPE_S *syspipe)
58 if(!syspipe || !syspipe->in.f)
59 return NULL;
61 return(fgets(str, size, syspipe->in.f));
64 int
65 pipe_readc(unsigned char *c, PIPE_S *syspipe)
67 int rv = 0;
69 if(!syspipe || !syspipe->in.f)
70 return -1;
72 do {
73 errno = 0;
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);
78 return(rv);
81 int
82 pipe_writec(int c, PIPE_S *syspipe)
84 unsigned char ch = (unsigned char)c;
85 int rv = 0;
87 if(!syspipe || !syspipe->out.f)
88 return -1;
91 rv = fwrite(&ch, sizeof(unsigned char), (size_t)1, syspipe->out.f);
92 while(!rv && ferror(syspipe->out.f) && errno == EINTR);
94 return(rv);
98 void
99 pipe_report_error(char *errormsg)
101 q_status_message(SM_ORDER, 3, 3, errormsg);