maint: update copyright
[gnulib.git] / m4 / ungetc.m4
1 # ungetc.m4 serial 3
2 dnl Copyright (C) 2009-2014 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.
6
7 AC_DEFUN_ONCE([gl_FUNC_UNGETC_WORKS],
8 [
9   AC_REQUIRE([AC_PROG_CC])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11
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+"))) return 1;
18            if (fputs ("abc", f) < 0) return 2;
19            rewind (f);
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],
31         [case "$host_os" in
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" ;;
36          esac
37         ])
38     ])
39   case "$gl_cv_func_ungetc_works" in
40     *yes) ;;
41     *)
42       AC_DEFINE([FUNC_UNGETC_BROKEN], [1],
43         [Define to 1 if ungetc is broken when used on arbitrary bytes.])
44       ;;
45   esac
46 ])