ref: 488049b6b56ab50d7be0e7dda5bdbbded5e5d2df
parent: 0ac77da6b080c9fdd74a036666ed560add8d3810
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Feb 13 07:22:56 EST 2018
[ar] Implement printout of time with -t This is a bit pedantic, but with this code we support not ascii platforms and platforms where time_t is not a scalar datatype.
--- a/ar/main.c
+++ b/ar/main.c
@@ -46,7 +46,7 @@
exit(1);
}
-FILE *
+static FILE *
openar(char *afile)
{
FILE *fp;
@@ -186,15 +186,18 @@
long val;
char *p, *q;
static char buf[10];
+ static char digits[] = "01234567";
siz = sizeof(hdr->ar_mode);
p = hdr->ar_mode;
- for (val = 0; siz-- > 0; val += c - '0') {
+ for (val = 0; siz-- > 0; val += c) {
+ val *= 7;
c = *p++;
- if ((q = strchr("01234567", c)) == NULL) {
+ if ((q = strchr(digits, c)) == NULL) {
fputs("ar: corrupted header\n", stderr);
exit(1);
}
+ c = q - digits;
}
letters(val >> 6, buf);
letters(val >> 3, buf+3);
@@ -203,6 +206,27 @@
return buf;
}
+static long long
+unixtime(struct ar_hdr *hdr)
+{
+ long long t;
+ int c, siz = sizeof(hdr->ar_date);
+ char *p, *q;
+ static char digits[] = "0123456789";
+
+ p = hdr->ar_date;
+ for (t = 0; siz-- > 0; t += c) {
+ t *= 10;
+ c = *p++;
+ if ((q = strchr(digits, c)) == NULL) {
+ fputs("ar:corrupted header\n", stderr);
+ exit(1);
+ }
+ c = q - digits;
+ }
+ return t;
+}
+
static void
list(struct arop *op, char *files[])
{
@@ -223,10 +247,11 @@
if (!vflag) {
printf("%s\n", op->fname);
} else {
+ t = totime(unixtime(hdr)),
printf("%s %d/%d\t%s %s\n",
perms(hdr),
hdr->ar_uid, hdr->ar_gid,
- "", /* TODO: ctime(&hdr->ar_date), */
+ ctime(&t),
op->fname);
}
}
--- a/ar/posix/stat.h
+++ b/ar/posix/stat.h
@@ -3,3 +3,4 @@
#include <sys/stat.h>
#include <unistd.h>
+#define totime(x) (x)