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],
18 AC_TRY_LINK([#include <stdio.h>], [ftello (stdin);],
19 [gl_cv_func_ftello=yes], [gl_cv_func_ftello=no])
21 if test $gl_cv_func_ftello = no; then
24 if test $gl_cv_var_stdin_large_offset = no; then
27 dnl Detect bug on Solaris.
28 dnl ftell and ftello produce incorrect results after putc that followed a
29 dnl getc call that reached EOF on Solaris. This is because the _IOREAD
30 dnl flag does not get cleared in this case, even though _IOWRT gets set,
31 dnl and ftell and ftello look whether the _IOREAD flag is set.
32 AC_REQUIRE([AC_CANONICAL_HOST])
33 AC_CACHE_CHECK([whether ftello works],
34 [gl_cv_func_ftello_works],
36 dnl Initial guess, used when cross-compiling or when /dev/tty cannot
40 # Guess no on Solaris.
41 solaris*) gl_cv_func_ftello_works="guessing no" ;;
42 # Guess yes otherwise.
43 *) gl_cv_func_ftello_works="guessing yes" ;;
50 #define TESTFILE "conftest.tmp"
56 /* Create a file with some contents. */
57 fp = fopen (TESTFILE, "w");
60 if (fwrite ("foogarsh", 1, 8, fp) < 8)
65 /* The file's contents is now "foogarsh". */
67 /* Try writing after reading to EOF. */
68 fp = fopen (TESTFILE, "r+");
71 if (fseek (fp, -1, SEEK_END))
73 if (!(getc (fp) == 'h'))
75 if (!(getc (fp) == EOF))
77 if (!(ftell (fp) == 8))
79 if (!(ftell (fp) == 8))
81 if (!(putc ('!', fp) == '!'))
83 if (!(ftell (fp) == 9))
85 if (!(fclose (fp) == 0))
87 fp = fopen (TESTFILE, "r");
92 if (!(fread (buf, 1, 10, fp) == 9))
94 if (!(memcmp (buf, "foogarsh!", 9) == 0))
97 if (!(fclose (fp) == 0))
100 /* The file's contents is now "foogarsh!". */
103 }], [gl_cv_func_ftello_works=yes], [gl_cv_func_ftello_works=no], [:])
105 case "$gl_cv_func_ftello_works" in
109 AC_DEFINE([FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE], [1],
110 [Define to 1 if the system's ftello function has the Solaris bug.])
115 if test $HAVE_FTELLO = 0 || test $REPLACE_FTELLO = 1; then
120 AC_DEFUN([gl_REPLACE_FTELLO],