ref: 0b30fc3454b5d07513cb66ddc7c1f57768a341ed
parent: 2605b26a91d34983201cf0e7c643e28eda4cb159
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Feb 19 10:11:05 EST 2018
[ar] Move stat after open the file We can call perror with fopen() (we don't know how stat is going to be implemented in non POSIX environments, so it is better to avoid the call to perror() in that case), and it will give a better error message than the one provided by stat.
--- a/ar/main.c
+++ b/ar/main.c
@@ -92,15 +92,15 @@
printf("%c - %s\n", letter, fname);
if (strlen(fname) > 16)
fprintf(stderr, "ar:%s: too long name\n", fname);
- if (stat(fname, &st) < 0) {
- fprintf(stderr, "ar:error getting '%s' attributes\n", fname);
- exit(1);
- }
if ((from = fopen(fname, "rb")) == NULL) {
fprintf(stderr,
"ar:opening member '%s':%s\n",
fname,
strerror(errno));
+ exit(1);
+ }
+ if (stat(fname, &st) < 0) {
+ fprintf(stderr, "ar:error getting '%s' attributes\n", fname);
exit(1);
}
strftime(mtime, sizeof(mtime), "%s", gmtime(&st.st_mtime));