2 dnl Copyright (C) 2007-2010 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_CACHE_CHECK([for ftello], [gl_cv_func_ftello],
20 [[#include <stdio.h>]],
21 [[ftello (stdin);]])],
22 [gl_cv_func_ftello=yes],
23 [gl_cv_func_ftello=no])
25 if test $gl_cv_func_ftello = no; then
28 if test $gl_cv_var_stdin_large_offset = no; then
31 dnl Detect bug on Solaris.
32 dnl ftell and ftello produce incorrect results after putc that followed a
33 dnl getc call that reached EOF on Solaris. This is because the _IOREAD
34 dnl flag does not get cleared in this case, even though _IOWRT gets set,
35 dnl and ftell and ftello look whether the _IOREAD flag is set.
36 AC_REQUIRE([AC_CANONICAL_HOST])
37 AC_CACHE_CHECK([whether ftello works],
38 [gl_cv_func_ftello_works],
40 dnl Initial guess, used when cross-compiling or when /dev/tty cannot
44 # Guess no on Solaris.
45 solaris*) gl_cv_func_ftello_works="guessing no" ;;
46 # Guess yes otherwise.
47 *) gl_cv_func_ftello_works="guessing yes" ;;
55 #define TESTFILE "conftest.tmp"
61 /* Create a file with some contents. */
62 fp = fopen (TESTFILE, "w");
65 if (fwrite ("foogarsh", 1, 8, fp) < 8)
70 /* The file's contents is now "foogarsh". */
72 /* Try writing after reading to EOF. */
73 fp = fopen (TESTFILE, "r+");
76 if (fseek (fp, -1, SEEK_END))
78 if (!(getc (fp) == 'h'))
80 if (!(getc (fp) == EOF))
82 if (!(ftell (fp) == 8))
84 if (!(ftell (fp) == 8))
86 if (!(putc ('!', fp) == '!'))
88 if (!(ftell (fp) == 9))
90 if (!(fclose (fp) == 0))
92 fp = fopen (TESTFILE, "r");
97 if (!(fread (buf, 1, 10, fp) == 9))
99 if (!(memcmp (buf, "foogarsh!", 9) == 0))
102 if (!(fclose (fp) == 0))
105 /* The file's contents is now "foogarsh!". */
109 [gl_cv_func_ftello_works=yes],
110 [gl_cv_func_ftello_works=no], [:])
112 case "$gl_cv_func_ftello_works" in
116 AC_DEFINE([FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE], [1],
117 [Define to 1 if the system's ftello function has the Solaris bug.])
122 if test $HAVE_FTELLO = 0 || test $REPLACE_FTELLO = 1; then
127 AC_DEFUN([gl_REPLACE_FTELLO],