2 dnl Copyright (C) 2009-2012 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+"))) return 1;
18 if (fputs ("abc", f) < 0) return 2;
20 if (fgetc (f) != 'a') return 3;
21 if (fgetc (f) != 'b') return 4;
22 if (ungetc ('d', f) != 'd') return 5;
23 if (ftell (f) != 1) return 6;
24 if (fgetc (f) != 'd') return 7;
25 if (ftell (f) != 2) return 8;
26 if (fseek (f, 0, SEEK_CUR) != 0) return 9;
27 if (ftell (f) != 2) return 10;
28 if (fgetc (f) != 'c') return 11;
29 fclose (f); remove ("conftest.tmp");])],
30 [gl_cv_func_ungetc_works=yes], [gl_cv_func_ungetc_works=no],
32 # Guess yes on glibc systems.
33 *-gnu*) gl_cv_func_ungetc_works="guessing yes" ;;
34 # If we don't know, assume the worst.
35 *) gl_cv_func_ungetc_works="guessing no" ;;
39 case "$gl_cv_func_ungetc_works" in
42 AC_DEFINE([FUNC_UNGETC_BROKEN], [1],
43 [Define to 1 if ungetc is broken when used on arbitrary bytes.])