Mercurial > hg > octave-kai > gnulib-hg
annotate m4/fflush.m4 @ 15606:f62f29997e98
unistd et al.: Don't assume <unistd.h> exists.
* m4/chdir-long.m4 (gl_FUNC_CHDIR_LONG): Don't include <unistd.h> if it
does not exist.
* m4/environ.m4 (gl_ENVIRON): Don't include <unistd.h> if it does not
exist. But include <stdlib.h>.
* m4/fcntl-o.m4 (gl_FCNTL_O_FLAGS): If <unistd.h> does not exist,
include <io.h> and <stdlib.h> instead. Don't test symbolink links if
symlink() does not exist.
* m4/fflush.m4 (gl_FUNC_FFLUSH_STDIN): If <unistd.h> does not exist,
include <io.h> instead.
* m4/free.m4 (gl_FUNC_FREE): Assume free(NULL) works on native Windows.
* m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): If <unistd.h> does not exist,
include <direct.h> instead.
* m4/getcwd-abort-bug.m4 (gl_FUNC_GETCWD_ABORT_BUG): Likewise.
* m4/getcwd-path-max.m4 (gl_FUNC_GETCWD_PATH_MAX): Likewise.
* m4/lseek.m4 (gl_FUNC_LSEEK): If <unistd.h> does not exist, include
<io.h> instead.
* m4/rename.m4 (gl_FUNC_RENAME): Assume rename() manages hard links
correctly if the system does not have hard links.
* m4/rmdir.m4 (gl_FUNC_RMDIR): If <unistd.h> does not exist, include
<direct.h> instead.
* m4/unistd_h.m4 (gl_UNISTD_H): If <unistd.h> does not exist, bypass
it when looking for function declarations.
* m4/unlink.m4 (gl_FUNC_UNLINK): If <unistd.h> does not exist, include
<direct.h> and <io.h> instead.
* doc/posix-headers/unistd.texi: More details about MSVC problem.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 11 Sep 2011 21:44:32 +0200 |
parents | e45dcf244493 |
children | 8250f2777afc |
rev | line source |
---|---|
15606
f62f29997e98
unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents:
14938
diff
changeset
|
1 # fflush.m4 serial 13 |
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 [ |
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], |
11017
95eb3a6eb21d
Make fflush-after-ungetc POSIX compliant on glibc systems.
Bruno Haible <bruno@clisp.org>
parents:
9976
diff
changeset
|
75 [dnl Pessimistically assume fflush is broken. |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
76 gl_cv_func_fflush_stdin=no]) |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
77 rm conftest.txt |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
78 ]) |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
79 ]) |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
80 |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9818
diff
changeset
|
81 # Prerequisites of lib/fflush.c. |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9818
diff
changeset
|
82 AC_DEFUN([gl_PREREQ_FFLUSH], |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9818
diff
changeset
|
83 [ |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9818
diff
changeset
|
84 AC_REQUIRE([AC_C_INLINE]) |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9818
diff
changeset
|
85 : |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9818
diff
changeset
|
86 ]) |