Mercurial > gnulib
annotate lib/isatty.c @ 17363:5a51fb7777a9
sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin
Problem reported by Marco Atzeri in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>.
* lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]:
Simply delegate to the system <sys/select.h> in this case too.
Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only
if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to
be needed on Solaris either.
* lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]:
Simply delgate to the system <sys/time.h> in this case.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 19 Mar 2013 09:08:47 -0700 |
parents | e542fd46ad6f |
children | 344018b6e5d7 |
rev | line source |
---|---|
16209 | 1 /* isatty() replacement. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
17185
diff
changeset
|
2 Copyright (C) 2012-2013 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 | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
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 | |
16213
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
30 #include "msvc-inval.h" |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
31 |
16209 | 32 /* Get _get_osfhandle(). */ |
33 #include "msvc-nothrow.h" | |
34 | |
16213
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
35 /* Optimized test whether a HANDLE refers to a console. |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
36 See <http://lists.gnu.org/archive/html/bug-gnulib/2009-08/msg00065.html>. */ |
16324
a37e8d313ade
select, poll, isatty: Avoid warnings on x86_64 mingw64.
Marc-André Lureau <marcandre.lureau@redhat.com>
parents:
16213
diff
changeset
|
37 #define IsConsoleHandle(h) (((intptr_t) (h) & 3) == 3) |
16209 | 38 |
16213
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
39 #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
|
40 static int |
16213
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
41 _isatty_nothrow (int fd) |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
42 { |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
43 int result; |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
44 |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
45 TRY_MSVC_INVAL |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
46 { |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
47 result = _isatty (fd); |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
48 } |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
49 CATCH_MSVC_INVAL |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
50 { |
16356
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
51 result = 0; |
16213
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 DONE_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 return result; |
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 #else |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
58 # define _isatty_nothrow _isatty |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
59 #endif |
64bc9fe46ccd
isatty: Support for MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
16209
diff
changeset
|
60 |
16356
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
61 /* 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
|
62 Return 0 and set errno if no. (ptsname_r relies on the errno value.) */ |
16209 | 63 int |
64 isatty (int fd) | |
65 { | |
16356
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
66 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
|
67 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
|
68 { |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
69 errno = EBADF; |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
70 return 0; |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
71 } |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
72 /* _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
|
73 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
|
74 if (_isatty_nothrow (fd)) |
16209 | 75 { |
16356
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
76 if (IsConsoleHandle (h)) |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
77 return 1; |
16209 | 78 } |
16356
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
79 errno = ENOTTY; |
2fa8e82affcc
isatty: Fix test failure of ptsname_r on native Windows.
Bruno Haible <bruno@clisp.org>
parents:
16324
diff
changeset
|
80 return 0; |
16209 | 81 } |