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])
11 AC_CACHE_CHECK([whether ungetc works on arbitrary bytes],
12 [gl_cv_func_ungetc_works],
13 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
16 if (!(f = fopen ("conftest.tmp", "w+"))) return 1;
17 if (fputs ("abc", f) < 0) return 2;
19 if (fgetc (f) != 'a') return 3;
20 if (fgetc (f) != 'b') return 4;
21 if (ungetc ('d', f) != 'd') return 5;
22 if (ftell (f) != 1) return 6;
23 if (fgetc (f) != 'd') return 7;
24 if (ftell (f) != 2) return 8;
25 if (fseek (f, 0, SEEK_CUR) != 0) return 9;
26 if (ftell (f) != 2) return 10;
27 if (fgetc (f) != 'c') return 11;
28 fclose (f); remove ("conftest.tmp");])],
29 [gl_cv_func_ungetc_works=yes], [gl_cv_func_ungetc_works=no],
30 [gl_cv_func_ungetc_works='guessing no'])
32 if test "$gl_cv_func_ungetc_works" != yes; then
33 AC_DEFINE([FUNC_UNGETC_BROKEN], [1],
34 [Define to 1 if ungetc is broken when used on arbitrary bytes.])