2 dnl Copyright (C) 2007-2015 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])
12 AC_REQUIRE([gl_SYS_TYPES_H])
14 dnl Persuade glibc <stdio.h> to declare ftello().
15 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
17 AC_CHECK_DECLS_ONCE([ftello])
18 if test $ac_cv_have_decl_ftello = no; then
22 AC_CACHE_CHECK([for ftello], [gl_cv_func_ftello],
26 [[#include <stdio.h>]],
27 [[ftello (stdin);]])],
28 [gl_cv_func_ftello=yes],
29 [gl_cv_func_ftello=no])
31 if test $gl_cv_func_ftello = no; then
34 if test $WINDOWS_64_BIT_OFF_T = 1; then
37 if test $gl_cv_var_stdin_large_offset = no; then
40 if test $REPLACE_FTELLO = 0; then
41 dnl Detect bug on Solaris.
42 dnl ftell and ftello produce incorrect results after putc that followed a
43 dnl getc call that reached EOF on Solaris. This is because the _IOREAD
44 dnl flag does not get cleared in this case, even though _IOWRT gets set,
45 dnl and ftell and ftello look whether the _IOREAD flag is set.
46 AC_REQUIRE([AC_CANONICAL_HOST])
47 AC_CACHE_CHECK([whether ftello works],
48 [gl_cv_func_ftello_works],
50 dnl Initial guess, used when cross-compiling or when /dev/tty cannot
54 # Guess no on Solaris.
55 solaris*) gl_cv_func_ftello_works="guessing no" ;;
56 # Guess yes otherwise.
57 *) gl_cv_func_ftello_works="guessing yes" ;;
65 #define TESTFILE "conftest.tmp"
71 /* Create a file with some contents. */
72 fp = fopen (TESTFILE, "w");
75 if (fwrite ("foogarsh", 1, 8, fp) < 8)
80 /* The file's contents is now "foogarsh". */
82 /* Try writing after reading to EOF. */
83 fp = fopen (TESTFILE, "r+");
86 if (fseek (fp, -1, SEEK_END))
88 if (!(getc (fp) == 'h'))
90 if (!(getc (fp) == EOF))
92 if (!(ftell (fp) == 8))
94 if (!(ftell (fp) == 8))
96 if (!(putc ('!', fp) == '!'))
98 if (!(ftell (fp) == 9))
100 if (!(fclose (fp) == 0))
102 fp = fopen (TESTFILE, "r");
107 if (!(fread (buf, 1, 10, fp) == 9))
109 if (!(memcmp (buf, "foogarsh!", 9) == 0))
112 if (!(fclose (fp) == 0))
115 /* The file's contents is now "foogarsh!". */
119 [gl_cv_func_ftello_works=yes],
120 [gl_cv_func_ftello_works=no], [:])
122 case "$gl_cv_func_ftello_works" in
126 AC_DEFINE([FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE], [1],
127 [Define to 1 if the system's ftello function has the Solaris bug.])
134 # Prerequisites of lib/ftello.c.
135 AC_DEFUN([gl_PREREQ_FTELLO],
137 dnl Native Windows has the function _ftelli64. mingw hides it, but mingw64
138 dnl makes it usable again.
139 AC_CHECK_FUNCS([_ftelli64])