X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Flseek.c;h=e6c21369d39aed68f04127b539d87953b930ab88;hb=a39d56cfe7d904b61aba940b20de06b94b6a60f8;hp=3d2fd42eb4e8857acfd70bd6747df5e1ce5b6e37;hpb=e461ff7387db733080824cb94b239d8d1d09c4f3;p=gnulib.git diff --git a/lib/lseek.c b/lib/lseek.c index 3d2fd42eb..e6c21369d 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-2011 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 @@ -20,9 +20,13 @@ /* 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 +#else +# include +#endif #include #undef lseek @@ -30,11 +34,29 @@ 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. */ - if (GetFileType ((HANDLE) _get_osfhandle (fd)) != FILE_TYPE_DISK) + HANDLE h = (HANDLE) _get_osfhandle (fd); + if (h == INVALID_HANDLE_VALUE) + { + errno = EBADF; + return -1; + } + if (GetFileType (h) != FILE_TYPE_DISK) + { + 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 return lseek (fd, offset, whence); }