annotate m4/fflush.m4 @ 9976:621cb9082339

Put system dependent routines into inline functions.
author Bruno Haible <bruno@clisp.org>
date Sat, 26 Apr 2008 16:42:17 +0200
parents fc76a5b22f64
children 95eb3a6eb21d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9976
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
1 # fflush.m4 serial 6
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
2
9818
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
3 # Copyright (C) 2007-2008 Free Software Foundation, Inc.
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 # This file is free software; the Free Software Foundation
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 # gives unlimited permission to copy and/or distribute it,
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 # with or without modifications, as long as this notice is preserved.
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8 dnl From Eric Blake
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 dnl Find out how to obey POSIX semantics of fflush(stdin) discarding
8699
996bed2dc377 Make fflush rely on fpurge.
Eric Blake <ebb9@byu.net>
parents: 8657
diff changeset
11 dnl unread input on seekable streams, rather than C99 undefined semantics.
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13 AC_DEFUN([gl_FUNC_FFLUSH],
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 [
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15 AC_CACHE_CHECK([whether fflush works on input streams],
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16 [gl_cv_func_fflush_stdin],
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 [echo hello world > conftest.txt
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18 AC_RUN_IFELSE([AC_LANG_PROGRAM(
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 [[
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20 #include <stdio.h>
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 #include <unistd.h>
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22 ]], [[FILE *f = fopen ("conftest.txt", "r");
8872
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents: 8718
diff changeset
23 char buffer[10];
9818
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
24 int fd;
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
25 if (f == NULL)
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
26 return 1;
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
27 fd = fileno (f);
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
28 if (fd < 0 || fread (buffer, 1, 5, f) != 5)
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 return 2;
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 /* For deterministic results, ensure f read a bigger buffer. */
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 if (lseek (fd, 0, SEEK_CUR) == 5)
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32 return 3;
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33 /* POSIX requires fflush-fseek to set file offset of fd. */
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
34 if (fflush (f) != 0 || fseek (f, 0, SEEK_CUR) != 0)
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 return 4;
9818
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
36 if (lseek (fd, 0, SEEK_CUR) != 5)
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
37 return 5;
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
38 /* TODO: Verify behaviour of fflush after ungetc, see
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
39 <http://lists.gnu.org/archive/html/bug-gnulib/2008-03/msg00131.html>. */
fc76a5b22f64 Disable the fflush-after-ungetc tests, since gnulib currently does not
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
40 return 0;
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 ]])], [gl_cv_func_fflush_stdin=yes], [gl_cv_func_fflush_stdin=no],
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 [dnl Pessimistically assume fflush is broken. This is wrong for
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43 dnl at least glibc and cygwin; but lib/fflush.c takes this into account.
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 gl_cv_func_fflush_stdin=no])
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 rm conftest.txt
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
46 ])
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
47 if test $gl_cv_func_fflush_stdin = no; then
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
48 gl_REPLACE_FFLUSH
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
49 fi
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 ])
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
52 AC_DEFUN([gl_REPLACE_FFLUSH],
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 [
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54 AC_LIBOBJ([fflush])
8713
aad7ea346fbf Make the combination of fflush and fseek/fseeko POSIX compliant.
Bruno Haible <bruno@clisp.org>
parents: 8700
diff changeset
55 AC_LIBOBJ([fseeko])
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 REPLACE_FFLUSH=1
8872
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents: 8718
diff changeset
58 REPLACE_FSEEKO=1
9976
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
59 gl_PREREQ_FFLUSH
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 ])
9976
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
61
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
62 # Prerequisites of lib/fflush.c.
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
63 AC_DEFUN([gl_PREREQ_FFLUSH],
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
64 [
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
65 AC_REQUIRE([AC_C_INLINE])
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
66 :
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
67 ])