From 20d7dcad96016ec0f63e6272ff5731b017c345d8 Mon Sep 17 00:00:00 2001 From: Philip Guenther Date: Thu, 9 Jan 2014 03:12:26 +0000 Subject: Update pax -v format to match "ls -l": display the year for dates in the future and include a space between the major and minor numbers for devices. Eliminate bogus handling of LC_TIME environment variable. Make strftime() format selection understandable by gcc -Wformat=2. ok millert@ --- bin/pax/extern.h | 3 +-- bin/pax/gen_subs.c | 37 ++++++++----------------------------- bin/pax/pax.c | 10 +--------- 3 files changed, 10 insertions(+), 40 deletions(-) (limited to 'bin/pax') diff --git a/bin/pax/extern.h b/bin/pax/extern.h index d50a8cc823f..90db24e632c 100644 --- a/bin/pax/extern.h +++ b/bin/pax/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.38 2014/01/08 04:48:29 guenther Exp $ */ +/* $OpenBSD: extern.h,v 1.39 2014/01/09 03:12:25 guenther Exp $ */ /* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */ /*- @@ -235,7 +235,6 @@ extern int rmleadslash; extern int exit_val; extern int docrc; extern char *dirptr; -extern char *ltmfrmt; extern char *argv0; extern FILE *listf; extern char *tempfile; diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c index 1d0540af675..d2e3c72a43e 100644 --- a/bin/pax/gen_subs.c +++ b/bin/pax/gen_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gen_subs.c,v 1.24 2014/01/08 05:52:47 guenther Exp $ */ +/* $OpenBSD: gen_subs.c,v 1.25 2014/01/09 03:12:25 guenther Exp $ */ /* $NetBSD: gen_subs.c,v 1.5 1995/03/21 09:07:26 cgd Exp $ */ /*- @@ -60,6 +60,8 @@ #define CURFRMT "%b %e %H:%M" #define OLDFRMT "%b %e %Y" #define NAME_WIDTH 8 +#define TIMEFMT(t, now) \ + (((t) + SIXMONTHS <= (now) || (t) > (now)) ? OLDFRMT : CURFRMT) /* * ls_list() @@ -72,7 +74,6 @@ ls_list(ARCHD *arcn, time_t now, FILE *fp) struct stat *sbp; char f_mode[MODELEN]; char f_date[DATELEN]; - const char *timefrmt; int term; term = zeroflag ? '\0' : '\n'; /* path termination character */ @@ -96,22 +97,11 @@ ls_list(ARCHD *arcn, time_t now, FILE *fp) sbp = &(arcn->sb); strmode(sbp->st_mode, f_mode); - if (ltmfrmt == NULL) { - /* - * no locale specified format. time format based on age - * compared to the time pax was started. - */ - if ((sbp->st_mtime + SIXMONTHS) <= now) - timefrmt = OLDFRMT; - else - timefrmt = CURFRMT; - } else - timefrmt = ltmfrmt; - /* * print file mode, link count, uid, gid and time */ - if (strftime(f_date,DATELEN,timefrmt,localtime(&(sbp->st_mtime))) == 0) + if (strftime(f_date, sizeof(f_date), TIMEFMT(sbp->st_mtime, now), + localtime(&(sbp->st_mtime))) == 0) f_date[0] = '\0'; (void)fprintf(fp, "%s%2u %-*.*s %-*.*s ", f_mode, sbp->st_nlink, NAME_WIDTH, UT_NAMESIZE, name_uid(sbp->st_uid, 1), @@ -121,7 +111,7 @@ ls_list(ARCHD *arcn, time_t now, FILE *fp) * print device id's for devices, or sizes for other nodes */ if ((arcn->type == PAX_CHR) || (arcn->type == PAX_BLK)) - (void)fprintf(fp, "%4lu,%4lu ", + (void)fprintf(fp, "%4lu, %4lu ", (unsigned long)MAJOR(sbp->st_rdev), (unsigned long)MINOR(sbp->st_rdev)); else { @@ -156,23 +146,12 @@ ls_tty(ARCHD *arcn) { char f_date[DATELEN]; char f_mode[MODELEN]; - const char *timefrmt; - - if (ltmfrmt == NULL) { - /* - * no locale specified format - */ - if ((arcn->sb.st_mtime + SIXMONTHS) <= time(NULL)) - timefrmt = OLDFRMT; - else - timefrmt = CURFRMT; - } else - timefrmt = ltmfrmt; + time_t now = time(NULL); /* * convert time to string, and print */ - if (strftime(f_date, DATELEN, timefrmt, + if (strftime(f_date, DATELEN, TIMEFMT(arcn->sb.st_mtime, now), localtime(&(arcn->sb.st_mtime))) == 0) f_date[0] = '\0'; strmode(arcn->sb.st_mode, f_mode); diff --git a/bin/pax/pax.c b/bin/pax/pax.c index ea5bfeab99a..511c9ca7c9f 100644 --- a/bin/pax/pax.c +++ b/bin/pax/pax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pax.c,v 1.34 2012/12/04 02:24:45 deraadt Exp $ */ +/* $OpenBSD: pax.c,v 1.35 2014/01/09 03:12:25 guenther Exp $ */ /* $NetBSD: pax.c,v 1.5 1996/03/26 23:54:20 mrg Exp $ */ /*- @@ -89,7 +89,6 @@ int rmleadslash = 0; /* remove leading '/' from pathnames */ int exit_val; /* exit value */ int docrc; /* check/create file crc */ char *dirptr; /* destination dir in a copy */ -char *ltmfrmt; /* -v locale time format (if any) */ char *argv0; /* root of argv[0] */ sigset_t s_mask; /* signal mask for cleanup critical sect */ FILE *listf = stderr; /* file pointer to print file list to */ @@ -366,13 +365,6 @@ gen_init(void) (void)setrlimit(RLIMIT_RSS , &reslimit); } - /* - * Handle posix locale - * - * set user defines time printing format for -v option - */ - ltmfrmt = getenv("LC_TIME"); - /* * signal handling to reset stored directory times and modes. Since * we deal with broken pipes via failed writes we ignore it. We also -- cgit v1.2.3