Mercurial > hg > octave-kai > gnulib-hg
annotate m4/fflush.m4 @ 14938:e45dcf244493
fflush: Move AC_LIBOBJ invocations to module description.
* m4/fflush.m4 (gl_REPLACE_FFLUSH): Remove macro.
(gl_FUNC_FFLUSH): Inline it here. Move AC_LIBOBJ and gl_PREREQ_FFLUSH
invocations from here...
* modules/fflush (configure.ac): ... to here.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 06 May 2011 13:21:22 +0200 |
parents | ae72d1a5b3d6 |
children | f62f29997e98 |
rev | line source |
---|---|
14938
e45dcf244493
fflush: Move AC_LIBOBJ invocations to module description.
Bruno Haible <bruno@clisp.org>
parents:
14697
diff
changeset
|
1 # fflush.m4 serial 12 |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
2 |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
13169
diff
changeset
|
3 # Copyright (C) 2007-2011 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 | 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 [ |
14938
e45dcf244493
fflush: Move AC_LIBOBJ invocations to module description.
Bruno Haible <bruno@clisp.org>
parents:
14697
diff
changeset
|
15 AC_REQUIRE([gl_STDIO_H_DEFAULTS]) |
14696
0fa7da6f7a52
fflush, fseeko: Respect rules for use of AC_LIBOBJ.
Bruno Haible <bruno@clisp.org>
parents:
14678
diff
changeset
|
16 gl_FUNC_FFLUSH_STDIN |
0fa7da6f7a52
fflush, fseeko: Respect rules for use of AC_LIBOBJ.
Bruno Haible <bruno@clisp.org>
parents:
14678
diff
changeset
|
17 if test $gl_cv_func_fflush_stdin = no; then |
14938
e45dcf244493
fflush: Move AC_LIBOBJ invocations to module description.
Bruno Haible <bruno@clisp.org>
parents:
14697
diff
changeset
|
18 REPLACE_FFLUSH=1 |
14696
0fa7da6f7a52
fflush, fseeko: Respect rules for use of AC_LIBOBJ.
Bruno Haible <bruno@clisp.org>
parents:
14678
diff
changeset
|
19 fi |
0fa7da6f7a52
fflush, fseeko: Respect rules for use of AC_LIBOBJ.
Bruno Haible <bruno@clisp.org>
parents:
14678
diff
changeset
|
20 ]) |
0fa7da6f7a52
fflush, fseeko: Respect rules for use of AC_LIBOBJ.
Bruno Haible <bruno@clisp.org>
parents:
14678
diff
changeset
|
21 |
0fa7da6f7a52
fflush, fseeko: Respect rules for use of AC_LIBOBJ.
Bruno Haible <bruno@clisp.org>
parents:
14678
diff
changeset
|
22 dnl Determine whether fflush works on input streams. |
0fa7da6f7a52
fflush, fseeko: Respect rules for use of AC_LIBOBJ.
Bruno Haible <bruno@clisp.org>
parents:
14678
diff
changeset
|
23 dnl Sets gl_cv_func_fflush_stdin. |
0fa7da6f7a52
fflush, fseeko: Respect rules for use of AC_LIBOBJ.
Bruno Haible <bruno@clisp.org>
parents:
14678
diff
changeset
|
24 |
0fa7da6f7a52
fflush, fseeko: Respect rules for use of AC_LIBOBJ.
Bruno Haible <bruno@clisp.org>
parents:
14678
diff
changeset
|
25 AC_DEFUN([gl_FUNC_FFLUSH_STDIN], |
0fa7da6f7a52
fflush, fseeko: Respect rules for use of AC_LIBOBJ.
Bruno Haible <bruno@clisp.org>
parents:
14678
diff
changeset
|
26 [ |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
27 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
|
28 [gl_cv_func_fflush_stdin], |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
29 [echo hello world > conftest.txt |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
30 AC_RUN_IFELSE([AC_LANG_PROGRAM( |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
31 [[ |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
32 #include <stdio.h> |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
33 #include <unistd.h> |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
34 ]], [[FILE *f = fopen ("conftest.txt", "r"); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
35 char buffer[10]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
36 int fd; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
37 int c; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
38 if (f == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
39 return 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
40 fd = fileno (f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
41 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
|
42 return 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
43 /* 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
|
44 if (lseek (fd, 0, SEEK_CUR) == 5) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
45 return 3; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
46 /* 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
|
47 on BSD systems and on mingw. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
48 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
|
49 return 4; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
50 if (lseek (fd, 0, SEEK_CUR) != 5) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
51 return 5; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
52 /* Verify behaviour of fflush after ungetc. See |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
53 <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
|
54 /* 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
|
55 mingw. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
56 c = fgetc (f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
57 ungetc (c, f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
58 fflush (f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
59 if (fgetc (f) != c) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
60 return 6; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
61 /* 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
|
62 on glibc 2.8 and on BSD systems. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
63 c = fgetc (f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
64 ungetc ('@', f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
65 fflush (f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
66 if (fgetc (f) != c) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
67 return 7; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
68 return 0; |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
69 ]])], [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
|
70 [dnl Pessimistically assume fflush is broken. |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
71 gl_cv_func_fflush_stdin=no]) |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
72 rm conftest.txt |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
73 ]) |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
74 ]) |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
75 |
9976
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 ]) |