Add script for determining the set of symbols to export from a library.
[gnulib.git] / m4 / ungetc.m4
blobab8757bab448d6560dfae65b3ea220f128d35293
1 # ungetc.m4 serial 6
2 dnl Copyright (C) 2009-2019 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN_ONCE([gl_FUNC_UNGETC_WORKS],
9   AC_REQUIRE([AC_PROG_CC])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12   AC_CACHE_CHECK([whether ungetc works on arbitrary bytes],
13     [gl_cv_func_ungetc_works],
14     [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
15 #include <stdio.h>
16       ]], [FILE *f;
17            if (!(f = fopen ("conftest.tmp", "w+")))
18              return 1;
19            if (fputs ("abc", f) < 0)
20              { fclose (f); return 2; }
21            rewind (f);
22            if (fgetc (f) != 'a')
23              { fclose (f); return 3; }
24            if (fgetc (f) != 'b')
25              { fclose (f); return 4; }
26            if (ungetc ('d', f) != 'd')
27              { fclose (f); return 5; }
28            if (ftell (f) != 1)
29              { fclose (f); return 6; }
30            if (fgetc (f) != 'd')
31              { fclose (f); return 7; }
32            if (ftell (f) != 2)
33              { fclose (f); return 8; }
34            if (fseek (f, 0, SEEK_CUR) != 0)
35              { fclose (f); return 9; }
36            if (ftell (f) != 2)
37              { fclose (f); return 10; }
38            if (fgetc (f) != 'c')
39              { fclose (f); return 11; }
40            fclose (f);
41            remove ("conftest.tmp");])],
42         [gl_cv_func_ungetc_works=yes], [gl_cv_func_ungetc_works=no],
43         [case "$host_os" in
44                                        # Guess yes on glibc and bionic systems.
45            *-gnu* | gnu* | *-android*) gl_cv_func_ungetc_works="guessing yes" ;;
46                                        # Guess yes on native Windows.
47            mingw*)                     gl_cv_func_ungetc_works="guessing yes" ;;
48                                        # If we don't know, assume the worst.
49            *)                          gl_cv_func_ungetc_works="guessing no" ;;
50          esac
51         ])
52     ])
53   case "$gl_cv_func_ungetc_works" in
54     *yes) ;;
55     *)
56       AC_DEFINE([FUNC_UNGETC_BROKEN], [1],
57         [Define to 1 if ungetc is broken when used on arbitrary bytes.])
58       ;;
59   esac