ref: 7e77d6f2279708fd26317673007cdab18299a532
parent: 28f4f2683abee60783f2bef64c48db65b950855b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Feb 14 09:09:21 EST 2018
[ar] Fix getnum() and add verbose to del()
--- a/ar/main.c
+++ b/ar/main.c
@@ -65,7 +65,7 @@
}
} else {
if (fgets(magic, sizeof(magic), fp) == NULL) {
- perror("ar:reading magic number");
+ perror("ar:error reading magic number");
exit(1);
}
if (strcmp(magic, ARMAG)) {
@@ -150,10 +150,7 @@
long siz, n;
struct ar_hdr *hdr = &op->hdr;
- if (vflag)
- printf("a - %s\n", op->fname);
-
- fwrite(&hdr, sizeof(hdr), 1, op->dst);
+ fwrite(hdr, sizeof(*hdr), 1, op->dst);
siz = op->size;
if ((siz & 1) == 1)
siz++;
@@ -309,8 +306,11 @@
static void
del(struct arop *op, char *files[])
{
- if (inlist(op->fname, files))
+ if (inlist(op->fname, files)) {
+ if (vflag)
+ printf("d - %s\n", op->fname);
return;
+ }
copy(op);
}
@@ -335,23 +335,22 @@
{
int c;
long long val;
- char *p, *q;
+ char *p;
static char digits[] = "0123456789";
- for (val = 0; size-- > 0; val += c) {
- if ((c = *p++) == ' ')
+ for (val = 0; size > 0; val += c) {
+ --size;
+ if ((c = *s++) == ' ')
break;
- if ((q = strchr(digits, c)) == NULL)
+ if ((p = strchr(digits, c)) == NULL)
return -1;
- if ((c = q - digits) >= base)
+ if ((c = p - digits) >= base)
return -1;
val *= base;
}
- if (size > 0) {
- while (size-- > 0 && *p++ != ' ')
- ;
- }
+ while (size > 0 && *s++ == ' ')
+ --size;
return (size == 0) ? val : -1;
}