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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16209
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 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
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16209
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Specification. */
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <unistd.h>
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 /* This replacement is enabled on native Windows. */
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 /* Get declarations of the Win32 API functions. */
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #define WIN32_LEAN_AND_MEAN
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <windows.h>
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 int
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 isatty (int fd)
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
93b0d3ad505e New module 'isatty'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 }