Back out the 2000-04-02 change.
[gnulib.git] / m4 / strftime.m4
1 #serial 12
2
3 dnl This macro is intended to be used solely in this file.
4 dnl These are the prerequisite macros for GNU's strftime.c replacement.
5 AC_DEFUN(_jm_STRFTIME_PREREQS,
6 [
7  dnl strftime.c uses localtime_r and the underyling system strftime
8  dnl if they exist.
9  AC_CHECK_FUNCS(localtime_r strftime)
10
11  AC_CHECK_HEADERS(limits.h)
12  AC_CHECK_FUNCS(bcopy tzset mempcpy memcpy memset)
13
14  # This defines (or not) HAVE_TZNAME and HAVE_TM_ZONE.
15  AC_STRUCT_TIMEZONE
16
17  AC_CHECK_FUNCS(mblen mbrlen)
18
19  AC_CHECK_MEMBER(struct tm.tm_gmtoff,
20                  [AC_DEFINE(HAVE_TM_GMTOFF, 1,
21                             [Define if struct tm has the tm_gmtoff member.])],
22                  ,
23                  [#include <time.h>])
24 ])
25
26 dnl Determine if the strftime function has all the features of the GNU one.
27 dnl
28 dnl From Jim Meyering.
29 dnl
30 AC_DEFUN(jm_FUNC_GNU_STRFTIME,
31 [AC_REQUIRE([AC_HEADER_TIME])dnl
32
33  _jm_STRFTIME_PREREQS
34
35  AC_REQUIRE([AC_C_CONST])dnl
36  AC_REQUIRE([AC_HEADER_STDC])dnl
37  AC_CHECK_HEADERS(sys/time.h)
38  AC_CACHE_CHECK([for working GNU strftime], jm_cv_func_working_gnu_strftime,
39   [AC_TRY_RUN(
40 [ /* Ulrich Drepper provided parts of the test program.  */
41 #if STDC_HEADERS
42 # include <stdlib.h>
43 #endif
44
45 #if TIME_WITH_SYS_TIME
46 # include <sys/time.h>
47 # include <time.h>
48 #else
49 # if HAVE_SYS_TIME_H
50 #  include <sys/time.h>
51 # else
52 #  include <time.h>
53 # endif
54 #endif
55
56 static int
57 compare (const char *fmt, const struct tm *tm, const char *expected)
58 {
59   char buf[99];
60   strftime (buf, 99, fmt, tm);
61   if (strcmp (buf, expected))
62     {
63 #ifdef SHOW_FAILURES
64       printf ("fmt: \"%s\", expected \"%s\", got \"%s\"\n",
65               fmt, expected, buf);
66 #endif
67       return 1;
68     }
69   return 0;
70 }
71
72 int
73 main ()
74 {
75   int n_fail = 0;
76   struct tm *tm;
77   time_t t = 738367; /* Fri Jan  9 13:06:07 1970 */
78   tm = gmtime (&t);
79
80   /* This is necessary to make strftime give consistent zone strings and
81      e.g., seconds since the epoch (%s).  */
82   putenv ("TZ=GMT0");
83
84 #undef CMP
85 #define CMP(Fmt, Expected) n_fail += compare ((Fmt), tm, (Expected))
86
87   CMP ("%-m", "1");             /* GNU */
88   CMP ("%A", "Friday");
89   CMP ("%^A", "FRIDAY");        /* The ^ is a GNU extension.  */
90   CMP ("%B", "January");
91   CMP ("%^B", "JANUARY");
92   CMP ("%C", "19");             /* POSIX.2 */
93   CMP ("%D", "01/09/70");       /* POSIX.2 */
94   CMP ("%F", "1970-01-09");
95   CMP ("%G", "1970");           /* GNU */
96   CMP ("%H", "13");
97   CMP ("%I", "01");
98   CMP ("%M", "06");
99   CMP ("%M", "06");
100   CMP ("%R", "13:06");          /* POSIX.2 */
101   CMP ("%S", "07");
102   CMP ("%T", "13:06:07");       /* POSIX.2 */
103   CMP ("%U", "01");
104   CMP ("%V", "02");
105   CMP ("%W", "01");
106   CMP ("%X", "13:06:07");
107   CMP ("%Y", "1970");
108   CMP ("%Z", "GMT");
109   CMP ("%_m", " 1");            /* GNU */
110   CMP ("%a", "Fri");
111   CMP ("%^a", "FRI");
112   CMP ("%b", "Jan");
113   CMP ("%^b", "JAN");
114   CMP ("%c", "Fri Jan  9 13:06:07 1970");
115   CMP ("%^c", "FRI JAN  9 13:06:07 1970");
116   CMP ("%d", "09");
117   CMP ("%e", " 9");             /* POSIX.2 */
118   CMP ("%g", "70");             /* GNU */
119   CMP ("%h", "Jan");            /* POSIX.2 */
120   CMP ("%^h", "JAN");
121   CMP ("%j", "009");
122   CMP ("%k", "13");             /* GNU */
123   CMP ("%l", " 1");             /* GNU */
124   CMP ("%m", "01");
125   CMP ("%n", "\n");             /* POSIX.2 */
126   CMP ("%p", "PM");
127   CMP ("%r", "01:06:07 PM");    /* POSIX.2 */
128   CMP ("%s", "738367");         /* GNU */
129   CMP ("%t", "\t");             /* POSIX.2 */
130   CMP ("%u", "5");              /* POSIX.2 */
131   CMP ("%w", "5");
132   CMP ("%x", "01/09/70");
133   CMP ("%y", "70");
134   CMP ("%z", "+0000");          /* GNU */
135
136   exit (n_fail ? 1 : 0);
137 }],
138              jm_cv_func_working_gnu_strftime=yes,
139              jm_cv_func_working_gnu_strftime=no,
140              dnl When crosscompiling, assume strftime is missing or broken.
141              jm_cv_func_working_gnu_strftime=no)
142   ])
143   if test $jm_cv_func_working_gnu_strftime = no; then
144     AC_SUBST(LIBOBJS)
145     LIBOBJS="$LIBOBJS strftime.$ac_objext"
146     AC_DEFINE_UNQUOTED(strftime, gnu_strftime,
147       [Define to gnu_strftime if the replacement function should be used.])
148   fi
149 ])
150
151 AC_DEFUN(jm_FUNC_STRFTIME,
152 [
153   _jm_STRFTIME_PREREQS
154   AC_REPLACE_FUNCS(strftime)
155 ])