X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Flseek.c;fp=lib%2Flseek.c;h=f0b76035e038254bd0f6dd1690def406fc25974f;hb=c7e61475680fa226bd9b8bdd469cd66914e630f5;hp=0000000000000000000000000000000000000000;hpb=800deb09b422a73c1212233a93839a223ff59678;p=debian%2Fgzip diff --git a/lib/lseek.c b/lib/lseek.c new file mode 100644 index 0000000..f0b7603 --- /dev/null +++ b/lib/lseek.c @@ -0,0 +1,64 @@ +/* -*- buffer-read-only: t -*- vi: set ro: */ +/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ +/* An lseek() function that detects pipes. + Copyright (C) 2007 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 + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + 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. */ + +#include + +/* Specification. */ +#include + +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +/* Windows platforms. */ +/* Get GetFileType. */ +# include +#else +# include +#endif +#include + +#undef lseek + +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) + { + 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); +}