From: Bruno Haible Date: Sat, 1 Jan 2011 00:50:01 +0000 (+0100) Subject: pread: Work around HP-UX 11 bugs. X-Git-Tag: v0.1~3419 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;ds=sidebyside;h=e86df7d62b265b41297f1afb0795efab89a5884e;p=gnulib.git pread: Work around HP-UX 11 bugs. * m4/pread.m4 (gl_FUNC_PREAD): When pread exists, test whether it works and set REPLACE_PREAD if not. * doc/posix-functions/pread.texi: Document the HP-UX 11 bugs. --- diff --git a/ChangeLog b/ChangeLog index 3cb5bbee2..6c7d45300 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-12-31 Bruno Haible + + pread: Work around HP-UX 11 bugs. + * m4/pread.m4 (gl_FUNC_PREAD): When pread exists, test whether it works + and set REPLACE_PREAD if not. + * doc/posix-functions/pread.texi: Document the HP-UX 11 bugs. + 2010-12-31 Eric Blake nl_langinfo: fix YESEXPR on Irix 6.5 diff --git a/doc/posix-functions/pread.texi b/doc/posix-functions/pread.texi index 743253b6f..0a4fc7c1c 100644 --- a/doc/posix-functions/pread.texi +++ b/doc/posix-functions/pread.texi @@ -11,6 +11,13 @@ Portability problems fixed by Gnulib: @item This function is missing on some platforms: HP-UX 10, mingw, BeOS. +@item +This function returns zero instead of positive values when large file support +is enabled on some platforms: +HP-UX 11.11. +@item +This function does not fail on pipes on some platforms: +HP-UX 11.31. @end itemize Portability problems not fixed by Gnulib: diff --git a/m4/pread.m4 b/m4/pread.m4 index f1425a6b1..15a92d77a 100644 --- a/m4/pread.m4 +++ b/m4/pread.m4 @@ -1,4 +1,4 @@ -# pread.m4 serial 2 +# pread.m4 serial 3 dnl Copyright (C) 2009-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -7,12 +7,82 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_PREAD], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + dnl Persuade glibc to declare pread(). AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) AC_CHECK_FUNCS_ONCE([pread]) - if test $ac_cv_func_pread = no; then + if test $ac_cv_func_pread = yes; then + dnl On HP-UX 11.11 with _FILE_OFFSET_BITS=64, pread() on a file returns 0 + dnl instead of a positive value. + dnl On HP-UX 11.31, pread() on a pipe does not fail. + AC_CACHE_CHECK([whether pread works], + [gl_cv_func_pread_works], + [ + dnl Initial guess, used when cross-compiling. +changequote(,)dnl + case "$host_os" in + # Guess no on HP-UX. + hpux*) gl_cv_func_pread_works="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_pread_works="guessing yes" ;; + esac +changequote([,])dnl + gl_save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include +#include + ]], + [[ +{ + int result = 0; + /* This test fails on HP-UX 11.00..11.11. */ + { + int fd = open ("conftest.c", O_RDONLY); + if (fd < 0) + result |= 1; + else + { + char byte_buf; + if (pread (fd, &byte_buf, 1, (off_t) 0) != 1) + result |= 2; + close (fd); + } + } + /* This test fails on HP-UX 11.00..11.31. */ + { + FILE *fp = popen ("echo", "r"); + if (fp == NULL) + result |= 1; + else + { + int fd = fileno (fp); + char byte_buf; + if (pread (fd, &byte_buf, 1, (off_t) 0) >= 0) + result |= 4; + pclose (fp); + } + } + return result; +}]])], + [gl_cv_func_pread_works=yes], + [gl_cv_func_pread_works=no], + [:]) + CPPFLAGS="$gl_save_CPPFLAGS" + ]) + case "$gl_cv_func_pread_works" in + *yes) ;; + *) REPLACE_PREAD=1 ;; + esac + else HAVE_PREAD=0 + fi + if test $HAVE_PREAD = 0 || test $REPLACE_PREAD = 1; then AC_LIBOBJ([pread]) fi ])