annotate m4/fflush.m4 @ 13169:b55181348b50

fseeko: Fix C++ test error on mingw.
author Bruno Haible <bruno@clisp.org>
date Mon, 05 Apr 2010 18:18:11 +0200
parents c2cbabec01dd
children 97fc9a21a8fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13169
b55181348b50 fseeko: Fix C++ test error on mingw.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
1 # fflush.m4 serial 8
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
2
12559
c2cbabec01dd update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents: 12421
diff changeset
3 # Copyright (C) 2007-2010 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");
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
23 char buffer[10];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
24 int fd;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
25 int c;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
26 if (f == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
27 return 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
28 fd = fileno (f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
29 if (fd < 0 || fread (buffer, 1, 5, f) != 5)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
30 return 2;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
31 /* For deterministic results, ensure f read a bigger buffer. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
32 if (lseek (fd, 0, SEEK_CUR) == 5)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
33 return 3;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
34 /* POSIX requires fflush-fseek to set file offset of fd. This fails
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
35 on BSD systems and on mingw. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
36 if (fflush (f) != 0 || fseek (f, 0, SEEK_CUR) != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
37 return 4;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
38 if (lseek (fd, 0, SEEK_CUR) != 5)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
39 return 5;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
40 /* Verify behaviour of fflush after ungetc. See
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
41 <http://www.opengroup.org/austin/aardvark/latest/xshbug3.txt> */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
42 /* Verify behaviour of fflush after a backup ungetc. This fails on
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
43 mingw. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
44 c = fgetc (f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
45 ungetc (c, f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
46 fflush (f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
47 if (fgetc (f) != c)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
48 return 6;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
49 /* Verify behaviour of fflush after a non-backup ungetc. This fails
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
50 on glibc 2.8 and on BSD systems. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
51 c = fgetc (f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
52 ungetc ('@', f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
53 fflush (f);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
54 if (fgetc (f) != c)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
55 return 7;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11017
diff changeset
56 return 0;
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 ]])], [gl_cv_func_fflush_stdin=yes], [gl_cv_func_fflush_stdin=no],
11017
95eb3a6eb21d Make fflush-after-ungetc POSIX compliant on glibc systems.
Bruno Haible <bruno@clisp.org>
parents: 9976
diff changeset
58 [dnl Pessimistically assume fflush is broken.
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59 gl_cv_func_fflush_stdin=no])
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 rm conftest.txt
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 ])
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 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
63 gl_REPLACE_FFLUSH
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
64 fi
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65 ])
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 AC_DEFUN([gl_REPLACE_FFLUSH],
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68 [
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
69 AC_LIBOBJ([fflush])
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
70 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
71 REPLACE_FFLUSH=1
9976
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
72 gl_PREREQ_FFLUSH
13169
b55181348b50 fseeko: Fix C++ test error on mingw.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
73 gl_REPLACE_FSEEKO
8657
05f21166eb81 * lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
74 ])
9976
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
75
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
76 # Prerequisites of lib/fflush.c.
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
77 AC_DEFUN([gl_PREREQ_FFLUSH],
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
78 [
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
79 AC_REQUIRE([AC_C_INLINE])
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
80 :
621cb9082339 Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents: 9818
diff changeset
81 ])