annotate lib/read.c @ 40231:9b3c79fdfe0b

strtod: fix clash with strtold Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817). * lib/strtod.c (compute_minus_zero, minus_zero): Simplify by remving the macro / external variable, and having just a function. User changed. This avoids the need for an external variable that might clash.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 11 Mar 2019 16:40:29 -0700
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 read() function.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19595
diff changeset
2 Copyright (C) 2008-2019 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
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18883
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
14583
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 <unistd.h>
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
19595
beb2ad957aca Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
23 #if defined _WIN32 && ! defined __CYGWIN__
15763
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
24
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
25 # include <errno.h>
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
26 # include <io.h>
14583
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
15763
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
28 # define WIN32_LEAN_AND_MEAN /* avoid including junk */
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
29 # include <windows.h>
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
30
18883
19886582ca8d Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
31 # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
19886582ca8d Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
32 # include "msvc-inval.h"
19886582ca8d Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
33 # endif
19886582ca8d Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
34 # if GNULIB_MSVC_NOTHROW
19886582ca8d Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
35 # include "msvc-nothrow.h"
19886582ca8d Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
36 # else
19886582ca8d Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
37 # include <io.h>
19886582ca8d Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
38 # endif
15763
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
39
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
40 # undef read
14583
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
15763
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
42 # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
17185
dd46d4e6beea dup, execute, fatal-signal, etc.: no 'static inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
43 static ssize_t
15763
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
44 read_nothrow (int fd, void *buf, size_t count)
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
45 {
15768
03d49ab0f9ae read: Fix last commit.
Bruno Haible <bruno@clisp.org>
parents: 15763
diff changeset
46 ssize_t result;
14583
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47
15763
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
48 TRY_MSVC_INVAL
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
49 {
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
50 result = read (fd, buf, count);
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
51 }
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
52 CATCH_MSVC_INVAL
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
53 {
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
54 result = -1;
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
55 errno = EBADF;
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
56 }
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
57 DONE_MSVC_INVAL;
14583
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58
15763
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
59 return result;
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
60 }
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
61 # else
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
62 # define read_nothrow read
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
63 # endif
15752
b86e9061a6d0 New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 14583
diff changeset
64
14583
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 ssize_t
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 rpl_read (int fd, void *buf, size_t count)
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 {
15763
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
68 ssize_t ret = read_nothrow (fd, buf, count);
14583
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
15763
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
70 # if GNULIB_NONBLOCKING
14583
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 if (ret < 0
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 && GetLastError () == ERROR_NO_DATA)
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 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
75 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
76 {
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 /* 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
78 DWORD state;
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 if (GetNamedPipeHandleState (h, &state, NULL, NULL, NULL, NULL, 0)
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 && (state & PIPE_NOWAIT) != 0)
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 /* 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
82 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
83 errno = EAGAIN;
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 }
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 }
15763
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
86 # endif
05e615abe919 read: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents: 15752
diff changeset
87
14583
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 return ret;
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 }
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90
8b22057e98d2 Support non-blocking pipe I/O in read() on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 #endif