2 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_FTELLO],
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_REQUIRE([AC_PROG_CC])
11 AC_REQUIRE([gl_STDIN_LARGE_OFFSET])
13 dnl Persuade glibc <stdio.h> to declare ftello().
14 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
16 AC_CHECK_DECLS_ONCE([ftello])
17 if test $ac_cv_have_decl_ftello = no; then
21 AC_CACHE_CHECK([for ftello], [gl_cv_func_ftello],
25 [[#include <stdio.h>]],
26 [[ftello (stdin);]])],
27 [gl_cv_func_ftello=yes],
28 [gl_cv_func_ftello=no])
30 if test $gl_cv_func_ftello = no; then
33 if test $gl_cv_var_stdin_large_offset = no; then
36 dnl Detect bug on Solaris.
37 dnl ftell and ftello produce incorrect results after putc that followed a
38 dnl getc call that reached EOF on Solaris. This is because the _IOREAD
39 dnl flag does not get cleared in this case, even though _IOWRT gets set,
40 dnl and ftell and ftello look whether the _IOREAD flag is set.
41 AC_REQUIRE([AC_CANONICAL_HOST])
42 AC_CACHE_CHECK([whether ftello works],
43 [gl_cv_func_ftello_works],
45 dnl Initial guess, used when cross-compiling or when /dev/tty cannot
49 # Guess no on Solaris.
50 solaris*) gl_cv_func_ftello_works="guessing no" ;;
51 # Guess yes otherwise.
52 *) gl_cv_func_ftello_works="guessing yes" ;;
60 #define TESTFILE "conftest.tmp"
66 /* Create a file with some contents. */
67 fp = fopen (TESTFILE, "w");
70 if (fwrite ("foogarsh", 1, 8, fp) < 8)
75 /* The file's contents is now "foogarsh". */
77 /* Try writing after reading to EOF. */
78 fp = fopen (TESTFILE, "r+");
81 if (fseek (fp, -1, SEEK_END))
83 if (!(getc (fp) == 'h'))
85 if (!(getc (fp) == EOF))
87 if (!(ftell (fp) == 8))
89 if (!(ftell (fp) == 8))
91 if (!(putc ('!', fp) == '!'))
93 if (!(ftell (fp) == 9))
95 if (!(fclose (fp) == 0))
97 fp = fopen (TESTFILE, "r");
102 if (!(fread (buf, 1, 10, fp) == 9))
104 if (!(memcmp (buf, "foogarsh!", 9) == 0))
107 if (!(fclose (fp) == 0))
110 /* The file's contents is now "foogarsh!". */
114 [gl_cv_func_ftello_works=yes],
115 [gl_cv_func_ftello_works=no], [:])
117 case "$gl_cv_func_ftello_works" in
121 AC_DEFINE([FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE], [1],
122 [Define to 1 if the system's ftello function has the Solaris bug.])
127 if test $HAVE_FTELLO = 0 || test $REPLACE_FTELLO = 1; then
132 AC_DEFUN([gl_REPLACE_FTELLO],