Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / gnulib-m4 / ungetc.m4
1 # ungetc.m4 serial 3
2 dnl Copyright (C) 2009-2015 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 and bionic systems.
33            *-gnu*|*-android*)
34                    gl_cv_func_ungetc_works="guessing yes" ;;
35                    # If we don't know, assume the worst.
36            *)      gl_cv_func_ungetc_works="guessing no" ;;
37          esac
38         ])
39     ])
40   case "$gl_cv_func_ungetc_works" in
41     *yes) ;;
42     *)
43       AC_DEFINE([FUNC_UNGETC_BROKEN], [1],
44         [Define to 1 if ungetc is broken when used on arbitrary bytes.])
45       ;;
46   esac
47 ])