shithub: scc

Download patch

ref: 795b53490a5f52bc535f83141e6e8000bf0275ae
parent: 488049b6b56ab50d7be0e7dda5bdbbded5e5d2df
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Feb 13 08:38:51 EST 2018

[ar] Fix long list

--- a/ar/main.c
+++ b/ar/main.c
@@ -191,12 +191,13 @@
 	siz = sizeof(hdr->ar_mode);
 	p = hdr->ar_mode;
 	for (val = 0; siz-- > 0; val += c) {
-		val *= 7;
-		c = *p++;
+		if ((c = *p++) == ' ')
+			break;
 		if ((q = strchr(digits, c)) == NULL) {
 			fputs("ar: corrupted header\n", stderr);
 			exit(1);
 		}
+		val *= 8;
 		c = q - digits;
 	}
 	letters(val >> 6, buf);
@@ -216,12 +217,13 @@
 
 	p = hdr->ar_date;
 	for (t = 0; siz-- > 0; t += c) {
-		t *= 10;
-		c = *p++;
+		if ((c = *p++) == ' ')
+			break;
 		if ((q = strchr(digits, c)) == NULL) {
 			fputs("ar:corrupted header\n", stderr);
 			exit(1);
 		}
+		t *= 10;
 		c = q - digits;
 	}
 	return t;
@@ -234,6 +236,7 @@
 	char **bp;
 	time_t t;
 	struct ar_hdr *hdr = &op->hdr;
+	char mtime[30];
 
 	if (*files == NULL) {
 		print = 1;
@@ -247,11 +250,12 @@
 	if (!vflag) {
 		printf("%s\n", op->fname);
 	} else {
-		t = totime(unixtime(hdr)),
+		t = totime(unixtime(hdr));
+		strftime(mtime, sizeof(mtime), "%c", localtime(&t));
 		printf("%s %d/%d\t%s %s\n",
 		       perms(hdr),
-		       hdr->ar_uid, hdr->ar_gid,
-		       ctime(&t),
+		       atol(hdr->ar_uid), atol(hdr->ar_gid),
+		       mtime,
 		       op->fname);
 	}
 }
@@ -289,9 +293,6 @@
 {
 	struct arop op;
 
-	if (*files == NULL)
-		return;
-
 	op.src = fp;
 	op.dst = tmp;
 	while (!ferror(fp) && fread(&op.hdr, sizeof(op.hdr), 1, fp) == 1) {
@@ -457,6 +458,8 @@
 		append(fp, argv);
 		break;
 	case 'd':
+		if (*argv == NULL)
+			return 0;
 		tmp = opentmp();
 		fun = del;
 		break;