summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2004-07-15 03:14:46 +0000
committerkientzle <kientzle@FreeBSD.org>2004-07-15 03:14:46 +0000
commit429d9c9041b575c1e0eb8588f146b6960077411a (patch)
tree349fb1a1d6ae71e492ca90274be6d011e18a5aaf /usr.bin/tar
parentdac3c49a71c2511a03cdebfd3dc79e5db11bdd62 (diff)
downloadFreeBSD-src-429d9c9041b575c1e0eb8588f146b6960077411a.zip
FreeBSD-src-429d9c9041b575c1e0eb8588f146b6960077411a.tar.gz
Make the day/month ordering dependent on the current locale by
testing the locale at program startup and setting a flag, then using that flag to determine appropriate strftime() arguments.
Diffstat (limited to 'usr.bin/tar')
-rw-r--r--usr.bin/tar/bsdtar.c6
-rw-r--r--usr.bin/tar/bsdtar.h1
-rw-r--r--usr.bin/tar/bsdtar_platform.h3
-rw-r--r--usr.bin/tar/read.c11
4 files changed, 17 insertions, 4 deletions
diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c
index 19a769d..d822851 100644
--- a/usr.bin/tar/bsdtar.c
+++ b/usr.bin/tar/bsdtar.c
@@ -47,6 +47,9 @@ struct option {
#define no_argument 0
#define required_argument 1
#endif
+#ifdef HAVE_NL_LANGINFO_D_MD_ORDER
+#include <langinfo.h>
+#endif
#include <locale.h>
#include <pwd.h>
#include <stdio.h>
@@ -163,6 +166,9 @@ main(int argc, char **argv)
if (setlocale(LC_ALL, "") == NULL)
bsdtar_warnc(bsdtar, 0, "Failed to set default locale");
+#ifdef HAVE_NL_LANGINFO_D_MD_ORDER
+ bsdtar->day_first = (*nl_langinfo(D_MD_ORDER) == 'd');
+#endif
mode = '\0';
possible_help_request = 0;
diff --git a/usr.bin/tar/bsdtar.h b/usr.bin/tar/bsdtar.h
index 79ec482..e4c1761 100644
--- a/usr.bin/tar/bsdtar.h
+++ b/usr.bin/tar/bsdtar.h
@@ -63,6 +63,7 @@ struct bsdtar {
char option_stdout; /* -p */
char option_unlink_first; /* -U */
char option_warn_links; /* -l */
+ char day_first; /* show day before month in -tv output */
/* If >= 0, then close this when done. */
int fd;
diff --git a/usr.bin/tar/bsdtar_platform.h b/usr.bin/tar/bsdtar_platform.h
index 8c5b75f..752423b 100644
--- a/usr.bin/tar/bsdtar_platform.h
+++ b/usr.bin/tar/bsdtar_platform.h
@@ -43,6 +43,9 @@
#define HAVE_CHFLAGS 1
#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec
+/* nl_langinfo supports D_MD_ORDER (FreeBSD extension) */
+#define HAVE_NL_LANGINFO_D_MD_ORDER 1
+
#if __FreeBSD__ > 4
#define HAVE_GETOPT_LONG 1
#define HAVE_POSIX_ACL 1
diff --git a/usr.bin/tar/read.c b/usr.bin/tar/read.c
index b99d2e0..34be304 100644
--- a/usr.bin/tar/read.c
+++ b/usr.bin/tar/read.c
@@ -209,6 +209,7 @@ list_item_verbose(struct bsdtar *bsdtar, struct archive_entry *entry)
char tmp[100];
size_t w;
const char *p;
+ const char *fmt;
time_t tim;
static time_t now;
@@ -277,11 +278,13 @@ list_item_verbose(struct bsdtar *bsdtar, struct archive_entry *entry)
/* Format the time using 'ls -l' conventions. */
tim = (time_t)st->st_mtime;
- if (tim < now - 6*30*24*60*60 || tim > now + 6*30*24*60*60)
- strftime(tmp, sizeof(tmp), "%b %e %Y", localtime(&tim));
+ if (abs(tim - now) > (365/2)*86400)
+ fmt = bsdtar->day_first ? "%e %b %Y" : "%b %e %Y";
else
- strftime(tmp, sizeof(tmp), "%b %e %R", localtime(&tim));
- safe_fprintf(out, " %s %s", tmp, archive_entry_pathname(entry));
+ fmt = bsdtar->day_first ? "%e %b %R" : "%b %e %R";
+ strftime(tmp, sizeof(tmp), fmt, localtime(&tim));
+ fprintf(out, " %s ", tmp);
+ safe_fprintf(out, "%s", archive_entry_pathname(entry));
/* Extra information for links. */
if (archive_entry_hardlink(entry)) /* Hard link */
OpenPOWER on IntegriCloud