X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Flseek.c;h=c7c39a6ad3552c76c11ae8e2af5109a424ae239e;hb=1276a2c5f24c0c932426aca9c899fa524d2443f2;hp=03830a9acdf9cbf9a4e3353ec06ecf51a4c960a6;hpb=d2d77c0eacd5e95e63cbea8abca35c70ce6a9a55;p=gnulib.git diff --git a/lib/lseek.c b/lib/lseek.c index 03830a9ac..c7c39a6ad 100644 --- a/lib/lseek.c +++ b/lib/lseek.c @@ -1,5 +1,5 @@ /* An lseek() function that detects pipes. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2014 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -12,17 +12,22 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + with this program; if not, see . */ #include /* Specification. */ #include -/* Get GetFileType. The replacement lseek is only used on mingw, so - this include can be unconditional. */ -#include +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +/* Windows platforms. */ +/* Get GetFileType. */ +# include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" +#else +# include +#endif #include #undef lseek @@ -30,6 +35,7 @@ off_t rpl_lseek (int fd, off_t offset, int whence) { +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* mingw lseek mistakenly succeeds on pipes, sockets, and terminals. */ HANDLE h = (HANDLE) _get_osfhandle (fd); if (h == INVALID_HANDLE_VALUE) @@ -42,5 +48,20 @@ rpl_lseek (int fd, off_t offset, int whence) errno = ESPIPE; return -1; } +#else + /* BeOS lseek mistakenly succeeds on pipes... */ + struct stat statbuf; + if (fstat (fd, &statbuf) < 0) + return -1; + if (!S_ISREG (statbuf.st_mode)) + { + errno = ESPIPE; + return -1; + } +#endif +#if _GL_WINDOWS_64_BIT_OFF_T + return _lseeki64 (fd, offset, whence); +#else return lseek (fd, offset, whence); +#endif }