3 # Copyright (C) 2007 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
10 dnl Find out how to obey POSIX semantics of fflush(stdin) discarding
11 dnl unread input on seekable streams, rather than C99 undefined semantics.
13 AC_DEFUN([gl_FUNC_FFLUSH],
15 AC_CACHE_CHECK([whether fflush works on input streams],
16 [gl_cv_func_fflush_stdin],
17 [echo hello world > conftest.txt
18 AC_RUN_IFELSE([AC_LANG_PROGRAM(
22 ]], [[FILE *f = fopen ("conftest.txt", "r");
25 if (!f || 0 > fd || fread (buffer, 1, 5, f) != 5)
27 /* For deterministic results, ensure f read a bigger buffer. */
28 if (lseek (fd, 0, SEEK_CUR) == 5)
30 /* POSIX requires fflush-fseek to set file offset of fd. */
31 if (fflush (f) != 0 || fseek (f, 0, SEEK_CUR) != 0)
33 return !(lseek (fd, 0, SEEK_CUR) == 5);
34 ]])], [gl_cv_func_fflush_stdin=yes], [gl_cv_func_fflush_stdin=no],
35 [dnl Pessimistically assume fflush is broken. This is wrong for
36 dnl at least glibc and cygwin; but lib/fflush.c takes this into account.
37 gl_cv_func_fflush_stdin=no])
40 if test $gl_cv_func_fflush_stdin = no; then
45 AC_DEFUN([gl_REPLACE_FFLUSH],
49 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
52 if test $gl_cv_func_fseeko = yes; then
53 AC_DEFINE([HAVE_FSEEKO], 1,
54 [Define to 1 if you have the fseeko() function or macro.])