Mercurial > hg > octave-shane > gnulib-hg
annotate lib/stdio-read.c @ 17616:cae23a655793
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Sat, 25 Jan 2014 06:40:43 -0800 (2014-01-25) |
parents | 344018b6e5d7 |
children |
rev | line source |
---|---|
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* POSIX compatible FILE stream read function. |
17587 | 2 Copyright (C) 2008-2014 Free Software Foundation, Inc. |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 Written by Bruno Haible <bruno@clisp.org>, 2011. |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 (at your option) any later version. |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 GNU General Public License for more details. |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 #include <config.h> |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 /* Specification. */ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include <stdio.h> |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 /* Replace these functions only if module 'nonblocking' is requested. */ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #if GNULIB_NONBLOCKING |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 /* On native Windows platforms, when read() is called on a non-blocking pipe |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 with an empty buffer, ReadFile() fails with error GetLastError() = |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 ERROR_NO_DATA, and read() in consequence fails with error EINVAL. This |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 read() function is at the basis of the function which fills the buffer of |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 a FILE stream. */ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 # include <errno.h> |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 # include <io.h> |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 # define WIN32_LEAN_AND_MEAN /* avoid including junk */ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 # include <windows.h> |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 |
15752
b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
14583
diff
changeset
|
40 # include "msvc-nothrow.h" |
b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
14583
diff
changeset
|
41 |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 # define CALL_WITH_ERRNO_FIX(RETTYPE, EXPRESSION, FAILED) \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 if (ferror (stream)) \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 return (EXPRESSION); \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 else \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 { \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 RETTYPE ret; \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 SetLastError (0); \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 ret = (EXPRESSION); \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 if (FAILED) \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 { \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 if (GetLastError () == ERROR_NO_DATA && ferror (stream)) \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 { \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 int fd = fileno (stream); \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 if (fd >= 0) \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 { \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 HANDLE h = (HANDLE) _get_osfhandle (fd); \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 if (GetFileType (h) == FILE_TYPE_PIPE) \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 { \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 /* h is a pipe or socket. */ \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 DWORD state; \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 if (GetNamedPipeHandleState (h, &state, NULL, NULL, \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 NULL, NULL, 0) \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 && (state & PIPE_NOWAIT) != 0) \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 /* h is a pipe in non-blocking mode. \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 Change errno from EINVAL to EAGAIN. */ \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 errno = EAGAIN; \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 } \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 } \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 } \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 } \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 return ret; \ |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 } |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 |
16927
849fe7deed28
Fix misspellings in comments.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16926
diff
changeset
|
75 /* Enable this function definition only if gnulib's <stdio.h> has prepared it. |
16926
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
76 Otherwise we get a function definition conflict with mingw64's <stdio.h>. */ |
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
77 # if GNULIB_SCANF |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 int |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 scanf (const char *format, ...) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 { |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 int retval; |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 va_list args; |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 va_start (args, format); |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 retval = vfscanf (stdin, format, args); |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 va_end (args); |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 return retval; |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 } |
16926
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
90 # endif |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 |
16927
849fe7deed28
Fix misspellings in comments.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16926
diff
changeset
|
92 /* Enable this function definition only if gnulib's <stdio.h> has prepared it. |
16926
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
93 Otherwise we get a function definition conflict with mingw64's <stdio.h>. */ |
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
94 # if GNULIB_FSCANF |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 int |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 fscanf (FILE *stream, const char *format, ...) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 { |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 int retval; |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 va_list args; |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 va_start (args, format); |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 retval = vfscanf (stream, format, args); |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 va_end (args); |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 return retval; |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 } |
16926
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
107 # endif |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 |
16927
849fe7deed28
Fix misspellings in comments.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16926
diff
changeset
|
109 /* Enable this function definition only if gnulib's <stdio.h> has prepared it. |
16926
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
110 Otherwise we get a function definition conflict with mingw64's <stdio.h>. */ |
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
111 # if GNULIB_VSCANF |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 int |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 vscanf (const char *format, va_list args) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
114 { |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 return vfscanf (stdin, format, args); |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 } |
16926
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
117 # endif |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 |
16927
849fe7deed28
Fix misspellings in comments.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16926
diff
changeset
|
119 /* Enable this function definition only if gnulib's <stdio.h> has prepared it. |
16926
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
120 Otherwise we get a function definition conflict with mingw64's <stdio.h>. */ |
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
121 # if GNULIB_VFSCANF |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
122 int |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 vfscanf (FILE *stream, const char *format, va_list args) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 #undef vfscanf |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 { |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 CALL_WITH_ERRNO_FIX (int, vfscanf (stream, format, args), ret == EOF) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 } |
16926
9e800db3ffe6
nonblocking: Avoid compilation error on mingw64.
Bruno Haible <bruno@clisp.org>
parents:
16727
diff
changeset
|
128 # endif |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 int |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
131 getchar (void) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
132 { |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
133 return fgetc (stdin); |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
134 } |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
135 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
136 int |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
137 fgetc (FILE *stream) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 #undef fgetc |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
139 { |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
140 CALL_WITH_ERRNO_FIX (int, fgetc (stream), ret == EOF) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
141 } |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
142 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
143 char * |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
144 fgets (char *s, int n, FILE *stream) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
145 #undef fgets |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 { |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
147 CALL_WITH_ERRNO_FIX (char *, fgets (s, n, stream), ret == NULL) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
148 } |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
149 |
16727
683cbe4ca79d
stdio: don't assume gets any more
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
150 /* We intentionally don't bother to fix gets. */ |
14583
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 size_t |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 fread (void *ptr, size_t s, size_t n, FILE *stream) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 #undef fread |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 { |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 CALL_WITH_ERRNO_FIX (size_t, fread (ptr, s, n, stream), ret < n) |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 } |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 # endif |
8b22057e98d2
Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 #endif |