Add support for tab-completion when selecting by rule
[alpine.git] / pith / pipe.c
blob501ef28a0cd121730ee49f1fb9e3f0f3fd9c2cdd
1 /*
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
32 * into it.
35 int
36 pipe_putc(int c, PIPE_S *syspipe)
38 if(!syspipe || !syspipe->out.f)
39 return -1;
41 return(fputc(c, syspipe->out.f));
44 int
45 pipe_puts(char *str, PIPE_S *syspipe)
47 if(!syspipe || !syspipe->out.f)
48 return -1;
50 return(fputs(str, syspipe->out.f));
53 char *
54 pipe_gets(char *str, int size, PIPE_S *syspipe)
56 if(!syspipe || !syspipe->in.f)
57 return NULL;
59 return(fgets(str, size, syspipe->in.f));
62 int
63 pipe_readc(unsigned char *c, PIPE_S *syspipe)
65 int rv = 0;
67 if(!syspipe || !syspipe->in.f)
68 return -1;
70 do {
71 errno = 0;
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);
76 return(rv);
79 int
80 pipe_writec(int c, PIPE_S *syspipe)
82 unsigned char ch = (unsigned char)c;
83 int rv = 0;
85 if(!syspipe || !syspipe->out.f)
86 return -1;
89 rv = fwrite(&ch, sizeof(unsigned char), (size_t)1, syspipe->out.f);
90 while(!rv && ferror(syspipe->out.f) && errno == EINTR);
92 return(rv);
96 void
97 pipe_report_error(char *errormsg)
99 q_status_message(SM_ORDER, 3, 3, errormsg);