summaryrefslogtreecommitdiffstats
path: root/contrib/cpio
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2005-10-01 06:37:41 +0000
committertjr <tjr@FreeBSD.org>2005-10-01 06:37:41 +0000
commit74e2490c69f4f0ca614cf2750563b95fbdbb27e3 (patch)
tree302e2d8ab7e2acf52b97d8eac35c80986f766d5d /contrib/cpio
parent7c13f400d503e0bfabba4d366034b84de37d3736 (diff)
downloadFreeBSD-src-74e2490c69f4f0ca614cf2750563b95fbdbb27e3.zip
FreeBSD-src-74e2490c69f4f0ca614cf2750563b95fbdbb27e3.tar.gz
Merge long_format() time formatting code and fixes for printf() format
errors from old copyin.c.
Diffstat (limited to 'contrib/cpio')
-rw-r--r--contrib/cpio/src/copyin.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/contrib/cpio/src/copyin.c b/contrib/cpio/src/copyin.c
index c8a21e5..a3e186a 100644
--- a/contrib/cpio/src/copyin.c
+++ b/contrib/cpio/src/copyin.c
@@ -31,6 +31,7 @@
#ifndef FNM_PATHNAME
#include <fnmatch.h>
#endif
+#include <langinfo.h>
#ifndef HAVE_LCHOWN
#define lchown chown
@@ -893,23 +894,25 @@ long_format (struct new_cpio_header *file_hdr, char *link_name)
char mbuf[11];
char tbuf[40];
time_t when;
+ char *ptbuf;
+ static int d_first = -1;
mode_string (file_hdr->c_mode, mbuf);
mbuf[10] = '\0';
/* Get time values ready to print. */
when = file_hdr->c_mtime;
- strcpy (tbuf, ctime (&when));
+ if (d_first < 0)
+ d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
if (current_time - when > 6L * 30L * 24L * 60L * 60L
|| current_time - when < 0L)
- {
- /* The file is older than 6 months, or in the future.
- Show the year instead of the time of day. */
- strcpy (tbuf + 11, tbuf + 19);
- }
- tbuf[16] = '\0';
+ ptbuf = d_first ? "%e %b %Y" : "%b %e %Y";
+ else
+ ptbuf = d_first ? "%e %b %R" : "%b %e %R";
+ strftime(tbuf, sizeof(tbuf), ptbuf, localtime(&when));
+ ptbuf = tbuf;
- printf ("%s %3u ", mbuf, file_hdr->c_nlink);
+ printf ("%s %3lu ", mbuf, file_hdr->c_nlink);
if (numeric_uid)
printf ("%-8u %-8u ", (unsigned int) file_hdr->c_uid,
@@ -920,12 +923,12 @@ long_format (struct new_cpio_header *file_hdr, char *link_name)
if ((file_hdr->c_mode & CP_IFMT) == CP_IFCHR
|| (file_hdr->c_mode & CP_IFMT) == CP_IFBLK)
- printf ("%3u, %3u ", file_hdr->c_rdev_maj,
+ printf ("%3lu, %3lu ", file_hdr->c_rdev_maj,
file_hdr->c_rdev_min);
else
printf ("%8lu ", file_hdr->c_filesize);
- printf ("%s ", tbuf + 4);
+ printf ("%s ", ptbuf);
print_name_with_quoting (file_hdr->c_name);
if (link_name)
@@ -978,7 +981,7 @@ print_name_with_quoting (register char *p)
break;
default:
- if (c > 040 && c < 0177)
+ if (isprint (c))
putchar (c);
else
printf ("\\%03o", (unsigned int) c);
OpenPOWER on IntegriCloud