Mercurial > gnulib
annotate lib/isatty.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 | e3496deebf30 |
rev | line source |
---|---|
16209 | 1 /* isatty() replacement. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2012-2019 Free Software Foundation, Inc. |
16209 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
16209 | 16 |
17 #include <config.h> | |
18 | |
19 /* Specification. */ | |
20 #include <unistd.h> | |
21 | |
22 /* This replacement is enabled on native Windows. */ | |
23 | |
16213
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
24 #include <errno.h> |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
25 |
16209 | 26 /* Get declarations of the Win32 API functions. */ |
27 #define WIN32_LEAN_AND_MEAN | |
28 #include <windows.h> | |
29 | |
18883
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
30 #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
|
31 # include "msvc-inval.h" |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
32 #endif |
16213
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
33 |
16209 | 34 /* Get _get_osfhandle(). */ |
18883
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
35 #if GNULIB_MSVC_NOTHROW |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
36 # include "msvc-nothrow.h" |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
37 #else |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
38 # include <io.h> |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
39 #endif |
16209 | 40 |
17699
36e26a0e7826
isatty: fix to work on windows 8
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17576
diff
changeset
|
41 static BOOL IsConsoleHandle (HANDLE h) |
36e26a0e7826
isatty: fix to work on windows 8
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17576
diff
changeset
|
42 { |
36e26a0e7826
isatty: fix to work on windows 8
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17576
diff
changeset
|
43 DWORD mode; |
36e26a0e7826
isatty: fix to work on windows 8
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17576
diff
changeset
|
44 return GetConsoleMode (h, &mode) != 0; |
36e26a0e7826
isatty: fix to work on windows 8
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17576
diff
changeset
|
45 } |
16209 | 46 |
16213
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
47 #if HAVE_MSVC_INVALID_PARAMETER_HANDLER |
17185
dd46d4e6beea
dup, execute, fatal-signal, etc.: no 'static inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16356
diff
changeset
|
48 static int |
16213
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
49 _isatty_nothrow (int fd) |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
50 { |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
51 int result; |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
52 |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
53 TRY_MSVC_INVAL |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
54 { |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
55 result = _isatty (fd); |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
56 } |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
57 CATCH_MSVC_INVAL |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
58 { |
16356
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
59 result = 0; |
16213
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
60 } |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
61 DONE_MSVC_INVAL; |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
62 |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
63 return result; |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
64 } |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
65 #else |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
66 # define _isatty_nothrow _isatty |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
67 #endif |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
68 |
16356
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
69 /* Determine whether FD refers to a console device. Return 1 if yes. |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
70 Return 0 and set errno if no. (ptsname_r relies on the errno value.) */ |
16209 | 71 int |
72 isatty (int fd) | |
73 { | |
16356
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
74 HANDLE h = (HANDLE) _get_osfhandle (fd); |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
75 if (h == INVALID_HANDLE_VALUE) |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
76 { |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
77 errno = EBADF; |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
78 return 0; |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
79 } |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
80 /* _isatty (fd) tests whether GetFileType of the handle is FILE_TYPE_CHAR. |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
81 But it does not set errno when it returns 0. */ |
16213
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
82 if (_isatty_nothrow (fd)) |
16209 | 83 { |
16356
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
84 if (IsConsoleHandle (h)) |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
85 return 1; |
16209 | 86 } |
16356
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
87 errno = ENOTTY; |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
88 return 0; |
16209 | 89 } |