Mercurial > gnulib
annotate lib/pipe-filter-aux.h @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 10eb9086bea0 |
children |
rev | line source |
---|---|
11758 | 1 /* Auxiliary code for filtering of data through a subprocess. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2001-2003, 2008-2019 Free Software Foundation, Inc. |
11758 | 3 Written by Bruno Haible <haible@clisp.cons.org>, 2009. |
4 | |
5 This program is free software: you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 3 of the License, or | |
8 (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
19190 | 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
11758 | 17 |
17473
1f9070ef79b0
headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
18 #ifndef _GL_INLINE_HEADER_BEGIN |
1f9070ef79b0
headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
19 #error "Please include config.h first." |
1f9070ef79b0
headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
20 #endif |
17101
99fa3b05f1c8
pipe-filter-gi, pipe-filter-ii: better use of 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
21 _GL_INLINE_HEADER_BEGIN |
99fa3b05f1c8
pipe-filter-gi, pipe-filter-ii: better use of 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
22 #ifndef PIPE_FILTER_AUX_INLINE |
99fa3b05f1c8
pipe-filter-gi, pipe-filter-ii: better use of 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
23 # define PIPE_FILTER_AUX_INLINE _GL_INLINE |
99fa3b05f1c8
pipe-filter-gi, pipe-filter-ii: better use of 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
24 #endif |
11758 | 25 |
26 #ifndef SSIZE_MAX | |
27 # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) | |
28 #endif | |
29 | |
30 /* We use a child process, and communicate through a bidirectional pipe. | |
31 To avoid deadlocks, let the child process decide when it wants to read | |
32 or to write, and let the parent behave accordingly. The parent uses | |
33 select() to know whether it must write or read. On platforms without | |
34 select(), we use non-blocking I/O. (This means the parent is busy | |
35 looping while waiting for the child. Not good. But hardly any platform | |
36 lacks select() nowadays.) */ | |
37 | |
18203
6adc50986538
pipe-filter-aux: undefine HAVE_SELECT on KLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
38 /* On BeOS and OS/2 kLIBC select() works only on sockets, not on normal file |
6adc50986538
pipe-filter-aux: undefine HAVE_SELECT on KLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
39 descriptors. */ |
6adc50986538
pipe-filter-aux: undefine HAVE_SELECT on KLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
40 #if defined __BEOS__ || defined __KLIBC__ |
11758 | 41 # undef HAVE_SELECT |
42 #endif | |
43 | |
44 #ifdef EINTR | |
45 | |
46 /* EINTR handling for close(), read(), write(), select(). | |
47 These functions can return -1/EINTR even though we don't have any | |
48 signal handlers set up, namely when we get interrupted via SIGSTOP. */ | |
49 | |
17101
99fa3b05f1c8
pipe-filter-gi, pipe-filter-ii: better use of 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
50 PIPE_FILTER_AUX_INLINE int |
11758 | 51 nonintr_close (int fd) |
52 { | |
53 int retval; | |
54 | |
55 do | |
56 retval = close (fd); | |
57 while (retval < 0 && errno == EINTR); | |
58 | |
59 return retval; | |
60 } | |
61 #undef close /* avoid warning related to gnulib module unistd */ | |
62 #define close nonintr_close | |
63 | |
17101
99fa3b05f1c8
pipe-filter-gi, pipe-filter-ii: better use of 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
64 PIPE_FILTER_AUX_INLINE ssize_t |
11758 | 65 nonintr_read (int fd, void *buf, size_t count) |
66 { | |
67 ssize_t retval; | |
68 | |
69 do | |
70 retval = read (fd, buf, count); | |
71 while (retval < 0 && errno == EINTR); | |
72 | |
73 return retval; | |
74 } | |
75 #define read nonintr_read | |
76 | |
17101
99fa3b05f1c8
pipe-filter-gi, pipe-filter-ii: better use of 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
77 PIPE_FILTER_AUX_INLINE ssize_t |
11758 | 78 nonintr_write (int fd, const void *buf, size_t count) |
79 { | |
80 ssize_t retval; | |
81 | |
82 do | |
83 retval = write (fd, buf, count); | |
84 while (retval < 0 && errno == EINTR); | |
85 | |
86 return retval; | |
87 } | |
88 #undef write /* avoid warning on VMS */ | |
89 #define write nonintr_write | |
90 | |
91 #endif | |
92 | |
93 /* Non-blocking I/O. */ | |
94 #if HAVE_SELECT | |
95 # define IS_EAGAIN(errcode) 0 | |
96 #else | |
97 # ifdef EWOULDBLOCK | |
98 # define IS_EAGAIN(errcode) ((errcode) == EAGAIN || (errcode) == EWOULDBLOCK) | |
99 # else | |
100 # define IS_EAGAIN(errcode) ((errcode) == EAGAIN) | |
101 # endif | |
102 #endif | |
17101
99fa3b05f1c8
pipe-filter-gi, pipe-filter-ii: better use of 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
103 |
99fa3b05f1c8
pipe-filter-gi, pipe-filter-ii: better use of 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
104 _GL_INLINE_HEADER_END |