X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Flseek.c;h=134e8b7d947f58bf26cdc96828f4427c056bd552;hb=030dc7afa953442437474140ac98ab4f8db56bc8;hp=03830a9acdf9cbf9a4e3353ec06ecf51a4c960a6;hpb=d2d77c0eacd5e95e63cbea8abca35c70ce6a9a55;p=gnulib.git diff --git a/lib/lseek.c b/lib/lseek.c index 03830a9ac..134e8b7d9 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,15 @@ /* 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 +36,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 +49,16 @@ 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 return lseek (fd, offset, whence); }