Mercurial > hg > octave-kai > gnulib-hg
annotate m4/fflush.m4 @ 17433:161070f4cae7
fflush, fseeko: port to musl cross-compiles
* lib/fseeko.c (fseeko): Assume that fflushing stdin works if
on some implementation that (1) is not known to be buggy,
(2) claims conformance to POSIX.1-2008 or later, and (3) is being
cross-compiled to so we can't easily check for lack of
conformance. This is for cross-compiling to musl.
Reported by Rich Felker in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-06/msg00043.html>.
* m4/fclose.m4 (gl_FUNC_FCLOSE):
* m4/fflush.m4 (gl_FUNC_FFLUSH):
* m4/fseeko.m4 (gl_FUNC_FSEEKO):
Adjust to above change.
* m4/fflush.m4 (gl_FUNC_FFLUSH_STDIN): Set gl_cv_func_fflush_stdin
to 'cross', not to 'no', when cross-compiling. AC_DEFINE
FUNC_FFLUSH_STDIN to 1, 0, -1 if fflushing stdin is known to work,
known not to work, or unknown.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 18 Jun 2013 13:07:00 -0700 |
parents | e542fd46ad6f |
children |
rev | line source |
---|---|
17433
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
1 # fflush.m4 serial 15 |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
2 |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
17187
diff
changeset
|
3 # Copyright (C) 2007-2013 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 |
17433
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
17 if test $gl_cv_func_fflush_stdin != yes; 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 [ |
15606
f62f29997e98
unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents:
14938
diff
changeset
|
27 AC_CHECK_HEADERS_ONCE([unistd.h]) |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
28 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
|
29 [gl_cv_func_fflush_stdin], |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
30 [echo hello world > conftest.txt |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
31 AC_RUN_IFELSE([AC_LANG_PROGRAM( |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
32 [[ |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
33 #include <stdio.h> |
15606
f62f29997e98
unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents:
14938
diff
changeset
|
34 #if HAVE_UNISTD_H |
f62f29997e98
unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents:
14938
diff
changeset
|
35 # include <unistd.h> |
f62f29997e98
unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents:
14938
diff
changeset
|
36 #else /* on Windows with MSVC */ |
f62f29997e98
unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents:
14938
diff
changeset
|
37 # include <io.h> |
f62f29997e98
unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents:
14938
diff
changeset
|
38 #endif |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
39 ]], [[FILE *f = fopen ("conftest.txt", "r"); |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
40 char buffer[10]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
41 int fd; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
42 int c; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
43 if (f == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
44 return 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
45 fd = fileno (f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
46 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
|
47 return 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
48 /* 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
|
49 if (lseek (fd, 0, SEEK_CUR) == 5) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
50 return 3; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
51 /* 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
|
52 on BSD systems and on mingw. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
53 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
|
54 return 4; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
55 if (lseek (fd, 0, SEEK_CUR) != 5) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
56 return 5; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
57 /* Verify behaviour of fflush after ungetc. See |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
58 <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
|
59 /* 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
|
60 mingw. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
61 c = fgetc (f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
62 ungetc (c, f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
63 fflush (f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
64 if (fgetc (f) != c) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
65 return 6; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
66 /* 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
|
67 on glibc 2.8 and on BSD systems. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
68 c = fgetc (f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
69 ungetc ('@', f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
70 fflush (f); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
71 if (fgetc (f) != c) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
72 return 7; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11017
diff
changeset
|
73 return 0; |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
74 ]])], [gl_cv_func_fflush_stdin=yes], [gl_cv_func_fflush_stdin=no], |
17433
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
75 [gl_cv_func_fflush_stdin=cross]) |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
76 rm conftest.txt |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
77 ]) |
17433
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
78 case $gl_cv_func_fflush_stdin in |
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
79 yes) gl_func_fflush_stdin=1 ;; |
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
80 no) gl_func_fflush_stdin=0 ;; |
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
81 *) gl_func_fflush_stdin='(-1)' ;; |
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
82 esac |
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
83 AC_DEFINE_UNQUOTED([FUNC_FFLUSH_STDIN], [$gl_func_fflush_stdin], |
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
84 [Define to 1 if fflush is known to work on stdin as per POSIX.1-2008, |
161070f4cae7
fflush, fseeko: port to musl cross-compiles
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
85 0 if fflush is known to not work, -1 if unknown.]) |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
86 ]) |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
87 |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9818
diff
changeset
|
88 # Prerequisites of lib/fflush.c. |
17187
4cd6b652c293
fflush, stat: no 'static inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
89 AC_DEFUN([gl_PREREQ_FFLUSH], [:]) |