Add this:
[gnulib.git] / m4 / off_t-format.m4
1 #serial 1                                                     -*- autoconf -*-
2
3 dnl FIXME
4 AC_DEFUN(jm_SYS_OFF_T_PRINTF_FORMAT,
5 [dnl
6   AC_REQUIRE([AC_TYPE_OFF_T])
7   AC_CHECK_HEADERS(string.h stdlinb.h)
8   AC_CACHE_CHECK([for printf format that works with type off_t],
9     jm_cv_sys_off_t_printf_format,
10   [
11    jm_cv_sys_off_t_printf_format=undef
12    for jm_fmt in '' L ll q; do
13      jm_OFF_T_FORMAT="$jm_fmt"
14      export jm_OFF_T_FORMAT
15      AC_TRY_RUN([
16 #      include <sys/types.h>
17 #      include <stdio.h>
18 #      if HAVE_STDLIB_H
19 #       include <stdlib.h>
20 #      endif
21 #      if HAVE_STRING_H
22 #       include <string.h>
23 #      endif
24        int
25        main()
26        {
27          static off_t x[] = {1, 255, 65535, 99999999};
28          char buf[50], fmt[50];
29
30          /* this should be one of these values: "", "L", "ll", "q"  */
31          char *f = getenv ("jm_OFF_T_FORMAT");
32
33          sprintf (fmt, "%%%sd %%%sx %%%sx %%%sd", f, f, f, f);
34          sprintf (buf, fmt, x[0], x[1], x[2], x[3]);
35          exit (strcmp (buf, "1 ff ffff 99999999"));
36        }
37        ], jm_cv_sys_off_t_printf_format=$jm_fmt; break
38        , dnl didn't work
39        dnl Cross compiling -- you lose.  Specify it via the cache.
40      )
41    done
42
43    # Die if none of the above worked.
44    # FIXME: If this failure become a problem that we can't work around,
45    # an alternative would be to arrange not to build od.
46    if test "$jm_cv_sys_off_t_printf_format" = undef; then
47      AC_MSG_ERROR(dnl
48        [couldn't find a printf format that works with the type, off_t])
49    fi
50   ])
51
52   AC_DEFINE_UNQUOTED(OFF_T_PRINTF_FORMAT_STRING,
53                      "$jm_cv_sys_off_t_printf_format",
54                      [printf format string for type off_t, without the `%'])
55 ])