scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit a41d347ad47938dbe4ebcc595a60adf489f94b3a
parent b7d5d80ba5eb854c17d8730b28a5323f7bcb2b94
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 19 Feb 2018 15:11:05 +0000

[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.

Diffstat:
Mar/main.c | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/ar/main.c b/ar/main.c @@ -92,10 +92,6 @@ archive(char *fname, FILE *to, char letter) 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", @@ -103,6 +99,10 @@ archive(char *fname, FILE *to, char letter) 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)); fprintf(to, "%-16.16s%-12s%-6u%-6u%-8o%-10llu`\n",