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