diff options
author | Simon Josefsson <jas@mocca.josefsson.org> | 2007-05-25 16:19:57 +0200 |
---|---|---|
committer | Simon Josefsson <jas@mocca.josefsson.org> | 2007-05-25 16:19:57 +0200 |
commit | 35808a63e0ed5611f01b94ad84a1374171e75e1a (patch) | |
tree | 8a0dd7a97014e2ebf7a26c2a852991aeb86453a9 | |
parent | 7d9131036e6d9d9261c7f1ce26243c44a9a6a985 (diff) | |
download | gnutls-35808a63e0ed5611f01b94ad84a1374171e75e1a.tar.gz |
Update.
-rw-r--r-- | lgl/lseek.c | 40 | ||||
-rw-r--r-- | lgl/m4/lseek.m4 | 30 |
2 files changed, 70 insertions, 0 deletions
diff --git a/lgl/lseek.c b/lgl/lseek.c new file mode 100644 index 0000000000..be9cd81c6d --- /dev/null +++ b/lgl/lseek.c @@ -0,0 +1,40 @@ +/* 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 Lesser General Public License as published by + the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser 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 <config.h> + +/* Specification. */ +#include <unistd.h> + +/* Get GetFileType. The replacement lseek is only used on mingw, so + this include can be unconditional. */ +#include <windows.h> +#include <errno.h> + +#undef lseek + +off_t +rpl_lseek (int fd, off_t offset, int whence) +{ + /* mingw lseek mistakenly succeeds on pipes, sockets, and terminals. */ + if (GetFileType ((HANDLE) _get_osfhandle (fd)) != FILE_TYPE_DISK) + { + errno = ESPIPE; + return -1; + } + return lseek (fd, offset, whence); +} diff --git a/lgl/m4/lseek.m4 b/lgl/m4/lseek.m4 new file mode 100644 index 0000000000..075c2f42c2 --- /dev/null +++ b/lgl/m4/lseek.m4 @@ -0,0 +1,30 @@ +# lseek.m4 serial 1 +dnl Copyright (C) 2007 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_LSEEK], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_REQUIRE([AC_PROG_CC]) + AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <unistd.h>], +[#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +/* mingw mistakenly returns 0 when trying to seek on pipes. */ + Choke me. +#endif])], + [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])]) + if test $gl_cv_func_lseek_pipe = no; then + gl_REPLACE_LSEEK + fi +]) + +AC_DEFUN([gl_REPLACE_LSEEK], +[ + AC_LIBOBJ([lseek]) + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + REPLACE_LSEEK=1 + AC_DEFINE([LSEEK_PIPE_BROKEN], [1], + [Define to 1 if lseek does not detect pipes.]) +]) |