X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Flseek.c;h=db8dbfb3e96392d4e194870959b29e1e61efeedf;hb=1a2869593e115e4a6c74aaa0b23ca612357403ce;hp=3d2fd42eb4e8857acfd70bd6747df5e1ce5b6e37;hpb=e461ff7387db733080824cb94b239d8d1d09c4f3;p=gnulib.git diff --git a/lib/lseek.c b/lib/lseek.c index 3d2fd42eb..db8dbfb3e 100644 --- a/lib/lseek.c +++ b/lib/lseek.c @@ -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); }