X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=m4%2Fftello.m4;h=ae9a4e61380b65ec6fb1534d69c88d94bc232382;hb=ad9a24a121ab3154f30d9d38d8243f41566d151e;hp=2dff6ee9a83c7ed17cfc4ffa913951b6fbc51756;hpb=b2e2010c7c902235b5efb5bd3c6529f61b093aa4;p=gnulib.git diff --git a/m4/ftello.m4 b/m4/ftello.m4 index 2dff6ee9a..ae9a4e613 100644 --- a/m4/ftello.m4 +++ b/m4/ftello.m4 @@ -1,5 +1,5 @@ -# ftello.m4 serial 5 -dnl Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +# ftello.m4 serial 7 +dnl Copyright (C) 2007-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, dnl with or without modifications, as long as this notice is preserved. @@ -10,7 +10,7 @@ AC_DEFUN([gl_FUNC_FTELLO], AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([gl_STDIN_LARGE_OFFSET]) - dnl Persuade glibc to declare fseeko(). + dnl Persuade glibc to declare ftello(). AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) AC_CACHE_CHECK([for ftello], [gl_cv_func_ftello], @@ -18,8 +18,101 @@ AC_DEFUN([gl_FUNC_FTELLO], AC_TRY_LINK([#include ], [ftello (stdin);], [gl_cv_func_ftello=yes], [gl_cv_func_ftello=no]) ]) - if test $gl_cv_func_ftello = no \ - || test $gl_cv_var_stdin_large_offset = no; then + if test $gl_cv_func_ftello = no; then + HAVE_FTELLO=0 + else + if test $gl_cv_var_stdin_large_offset = no; then + REPLACE_FTELLO=1 + else + dnl Detect bug on Solaris. + dnl ftell and ftello produce incorrect results after putc that followed a + dnl getc call that reached EOF on Solaris. This is because the _IOREAD + dnl flag does not get cleared in this case, even though _IOWRT gets set, + dnl and ftell and ftello look whether the _IOREAD flag is set. + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_CACHE_CHECK([whether ftello works], + [gl_cv_func_ftello_works], + [ + dnl Initial guess, used when cross-compiling or when /dev/tty cannot + dnl be opened. +changequote(,)dnl + case "$host_os" in + # Guess no on Solaris. + solaris*) gl_cv_func_ftello_works="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_ftello_works="guessing yes" ;; + esac +changequote([,])dnl + AC_TRY_RUN([ +#include +#include +#include +#define TESTFILE "conftest.tmp" +int +main (void) +{ + FILE *fp; + + /* Create a file with some contents. */ + fp = fopen (TESTFILE, "w"); + if (fp == NULL) + return 70; + if (fwrite ("foogarsh", 1, 8, fp) < 8) + return 71; + if (fclose (fp)) + return 72; + + /* The file's contents is now "foogarsh". */ + + /* Try writing after reading to EOF. */ + fp = fopen (TESTFILE, "r+"); + if (fp == NULL) + return 73; + if (fseek (fp, -1, SEEK_END)) + return 74; + if (!(getc (fp) == 'h')) + return 1; + if (!(getc (fp) == EOF)) + return 2; + if (!(ftell (fp) == 8)) + return 3; + if (!(ftell (fp) == 8)) + return 4; + if (!(putc ('!', fp) == '!')) + return 5; + if (!(ftell (fp) == 9)) + return 6; + if (!(fclose (fp) == 0)) + return 7; + fp = fopen (TESTFILE, "r"); + if (fp == NULL) + return 75; + { + char buf[10]; + if (!(fread (buf, 1, 10, fp) == 9)) + return 10; + if (!(memcmp (buf, "foogarsh!", 9) == 0)) + return 11; + } + if (!(fclose (fp) == 0)) + return 12; + + /* The file's contents is now "foogarsh!". */ + + return 0; +}], [gl_cv_func_ftello_works=yes], [gl_cv_func_ftello_works=no], [:]) + ]) + case "$gl_cv_func_ftello_works" in + *yes) ;; + *) + REPLACE_FTELLO=1 + AC_DEFINE([FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE], [1], + [Define to 1 if the system's ftello function has the Solaris bug.]) + ;; + esac + fi + fi + if test $HAVE_FTELLO = 0 || test $REPLACE_FTELLO = 1; then gl_REPLACE_FTELLO fi ]) @@ -27,6 +120,4 @@ AC_DEFUN([gl_FUNC_FTELLO], AC_DEFUN([gl_REPLACE_FTELLO], [ AC_LIBOBJ([ftello]) - AC_REQUIRE([gl_STDIO_H_DEFAULTS]) - REPLACE_FTELLO=1 ])