summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-04-03 07:38:41 +0000
committerJim Meyering <jim@meyering.net>2000-04-03 07:38:41 +0000
commit5ca6863e97423997b06dc3a1072c3f75d354733c (patch)
tree2d343464b94a7d4d1697d7072b27e949364fcee6 /src
parentafe1e8e12636337378e33b8347c5fdf3e4243b1d (diff)
downloadcoreutils-5ca6863e97423997b06dc3a1072c3f75d354733c.tar.xz
Include <langinfo.h> if it exists.
(DATE_FMT_LANGINFO): New macro. (show_date): Use it to get the locale-specific default format for "date" if it exists.
Diffstat (limited to 'src')
-rw-r--r--src/date.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/date.c b/src/date.c
index ef8563a7f..555bf7eeb 100644
--- a/src/date.c
+++ b/src/date.c
@@ -21,6 +21,9 @@
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+#if HAVE_LANGINFO_H
+# include <langinfo.h>
+#endif
#include "system.h"
#include "argmatch.h"
@@ -106,6 +109,12 @@ static struct option const long_options[] =
#define MAYBE_SET_TZ_UTC0 \
do { if (universal_time) set_tz (TZ_UTC0); } while (0)
+#ifdef _DATE_FMT
+# define DATE_FMT_LANGINFO() nl_langinfo (_DATE_FMT)
+#else
+# define DATE_FMT_LANGINFO() ""
+#endif
+
void
usage (int status)
{
@@ -490,13 +499,17 @@ show_date (const char *format, time_t when)
in the RFC format to %Z; this gives, however, an invalid
RFC time format outside the continental United States and GMT. */
- format = (rfc_format
- ? (universal_time
- ? "%a, %_d %b %Y %H:%M:%S GMT"
- : "%a, %_d %b %Y %H:%M:%S %z")
- : (iso_8601_format
- ? iso_format_string[iso_8601_format][universal_time]
- : "%a %b %e %H:%M:%S %Z %Y"));
+ if (rfc_format)
+ format = (universal_time
+ ? "%a, %_d %b %Y %H:%M:%S GMT"
+ : "%a, %_d %b %Y %H:%M:%S %z");
+ else if (iso_8601_format)
+ format = iso_format_string[iso_8601_format][universal_time];
+ else
+ {
+ char *date_fmt = DATE_FMT_LANGINFO ();
+ format = *date_fmt ? date_fmt : "%a %b %e %H:%M:%S %Z %Y";
+ }
}
else if (*format == '\0')
{