Mercurial > gnulib
annotate lib/lseek.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 |
---|---|
8872 | 1 /* An lseek() function that detects pipes. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16795
diff
changeset
|
2 Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. |
8872 | 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 2, or (at your option) | |
7 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 along | |
16366
bb182ee4a09d
maint: replace FSF snail-mail addresses with URLs
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
15 with this program; if not, see <http://www.gnu.org/licenses/>. */ |
8872 | 16 |
17 #include <config.h> | |
18 | |
19 /* Specification. */ | |
20 #include <unistd.h> | |
21 | |
9153
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
22 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
23 /* Windows platforms. */ |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
24 /* Get GetFileType. */ |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
25 # include <windows.h> |
15752
b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
26 /* Get _get_osfhandle. */ |
b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
27 # include "msvc-nothrow.h" |
9153
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
28 #else |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
29 # include <sys/stat.h> |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
30 #endif |
8872 | 31 #include <errno.h> |
32 | |
33 #undef lseek | |
34 | |
35 off_t | |
36 rpl_lseek (int fd, off_t offset, int whence) | |
37 { | |
9153
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
38 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
8872 | 39 /* mingw lseek mistakenly succeeds on pipes, sockets, and terminals. */ |
8877 | 40 HANDLE h = (HANDLE) _get_osfhandle (fd); |
41 if (h == INVALID_HANDLE_VALUE) | |
42 { | |
43 errno = EBADF; | |
44 return -1; | |
45 } | |
46 if (GetFileType (h) != FILE_TYPE_DISK) | |
8872 | 47 { |
48 errno = ESPIPE; | |
49 return -1; | |
50 } | |
9153
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
51 #else |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
52 /* BeOS lseek mistakenly succeeds on pipes... */ |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
53 struct stat statbuf; |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
54 if (fstat (fd, &statbuf) < 0) |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
55 return -1; |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
56 if (!S_ISREG (statbuf.st_mode)) |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
57 { |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
58 errno = ESPIPE; |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
59 return -1; |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
60 } |
f03082407073
Work around lseek bug on BeOS.
Bruno Haible <bruno@clisp.org>
parents:
8877
diff
changeset
|
61 #endif |
16795
6a9ea5d7b466
Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
62 #if _GL_WINDOWS_64_BIT_OFF_T |
6a9ea5d7b466
Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
63 return _lseeki64 (fd, offset, whence); |
6a9ea5d7b466
Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
64 #else |
8872 | 65 return lseek (fd, offset, whence); |
16795
6a9ea5d7b466
Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
66 #endif |
8872 | 67 } |