Back out the 2000-04-02 change.
[gnulib.git] / m4 / strftime.m4
1 #serial 13
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   /* Undefine this in case the configure-time putenv test has defined it
81      to something else.  The use we make of this function here doesn't
82      require the added functionality of the replacement one.  */
83 #undef putenv
84
85   /* This is necessary to make strftime give consistent zone strings and
86      e.g., seconds since the epoch (%s).  */
87   putenv ("TZ=GMT0");
88
89 #undef CMP
90 #define CMP(Fmt, Expected) n_fail += compare ((Fmt), tm, (Expected))
91
92   CMP ("%-m", "1");             /* GNU */
93   CMP ("%A", "Friday");
94   CMP ("%^A", "FRIDAY");        /* The ^ is a GNU extension.  */
95   CMP ("%B", "January");
96   CMP ("%^B", "JANUARY");
97   CMP ("%C", "19");             /* POSIX.2 */
98   CMP ("%D", "01/09/70");       /* POSIX.2 */
99   CMP ("%F", "1970-01-09");
100   CMP ("%G", "1970");           /* GNU */
101   CMP ("%H", "13");
102   CMP ("%I", "01");
103   CMP ("%M", "06");
104   CMP ("%M", "06");
105   CMP ("%R", "13:06");          /* POSIX.2 */
106   CMP ("%S", "07");
107   CMP ("%T", "13:06:07");       /* POSIX.2 */
108   CMP ("%U", "01");
109   CMP ("%V", "02");
110   CMP ("%W", "01");
111   CMP ("%X", "13:06:07");
112   CMP ("%Y", "1970");
113   CMP ("%Z", "GMT");
114   CMP ("%_m", " 1");            /* GNU */
115   CMP ("%a", "Fri");
116   CMP ("%^a", "FRI");
117   CMP ("%b", "Jan");
118   CMP ("%^b", "JAN");
119   CMP ("%c", "Fri Jan  9 13:06:07 1970");
120   CMP ("%^c", "FRI JAN  9 13:06:07 1970");
121   CMP ("%d", "09");
122   CMP ("%e", " 9");             /* POSIX.2 */
123   CMP ("%g", "70");             /* GNU */
124   CMP ("%h", "Jan");            /* POSIX.2 */
125   CMP ("%^h", "JAN");
126   CMP ("%j", "009");
127   CMP ("%k", "13");             /* GNU */
128   CMP ("%l", " 1");             /* GNU */
129   CMP ("%m", "01");
130   CMP ("%n", "\n");             /* POSIX.2 */
131   CMP ("%p", "PM");
132   CMP ("%r", "01:06:07 PM");    /* POSIX.2 */
133   CMP ("%s", "738367");         /* GNU */
134   CMP ("%t", "\t");             /* POSIX.2 */
135   CMP ("%u", "5");              /* POSIX.2 */
136   CMP ("%w", "5");
137   CMP ("%x", "01/09/70");
138   CMP ("%y", "70");
139   CMP ("%z", "+0000");          /* GNU */
140
141   exit (n_fail ? 1 : 0);
142 }],
143              jm_cv_func_working_gnu_strftime=yes,
144              jm_cv_func_working_gnu_strftime=no,
145              dnl When crosscompiling, assume strftime is missing or broken.
146              jm_cv_func_working_gnu_strftime=no)
147   ])
148   if test $jm_cv_func_working_gnu_strftime = no; then
149     AC_SUBST(LIBOBJS)
150     LIBOBJS="$LIBOBJS strftime.$ac_objext"
151     AC_DEFINE_UNQUOTED(strftime, gnu_strftime,
152       [Define to gnu_strftime if the replacement function should be used.])
153   fi
154 ])
155
156 AC_DEFUN(jm_FUNC_STRFTIME,
157 [
158   _jm_STRFTIME_PREREQS
159   AC_REPLACE_FUNCS(strftime)
160 ])