2 dnl Copyright (C) 2009-2020 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([[
17 if (!(f = fopen ("conftest.tmp", "w+")))
19 if (fputs ("abc", f) < 0)
20 { fclose (f); return 2; }
23 { fclose (f); return 3; }
25 { fclose (f); return 4; }
26 if (ungetc ('d', f) != 'd')
27 { fclose (f); return 5; }
29 { fclose (f); return 6; }
31 { fclose (f); return 7; }
33 { fclose (f); return 8; }
34 if (fseek (f, 0, SEEK_CUR) != 0)
35 { fclose (f); return 9; }
37 { fclose (f); return 10; }
39 { fclose (f); return 11; }
41 remove ("conftest.tmp");
43 [gl_cv_func_ungetc_works=yes], [gl_cv_func_ungetc_works=no],
45 # Guess yes on glibc systems.
46 *-gnu* | gnu*) gl_cv_func_ungetc_works="guessing yes" ;;
47 # Guess yes on musl systems.
48 *-musl*) gl_cv_func_ungetc_works="guessing yes" ;;
49 # Guess yes on bionic systems.
50 *-android*) gl_cv_func_ungetc_works="guessing yes" ;;
51 # Guess yes on native Windows.
52 mingw*) gl_cv_func_ungetc_works="guessing yes" ;;
53 # If we don't know, obey --enable-cross-guesses.
54 *) gl_cv_func_ungetc_works="$gl_cross_guess_normal" ;;
58 case "$gl_cv_func_ungetc_works" in
61 AC_DEFINE([FUNC_UNGETC_BROKEN], [1],
62 [Define to 1 if ungetc is broken when used on arbitrary bytes.])