scc

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

commit 6781c8de92991e861efec7bae7f96d64b2c9bb4b
parent 7d51a01bf4af2dabf73154251864a977bac40bba
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  6 Mar 2018 11:12:36 +0100

[ar/nm] Synchronize the file name criteria

We get rid of final / added in COFF and elf.

Diffstat:
Mar/main.c | 13+++++++------
Mnm/main.c | 19++++++++++---------
2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/ar/main.c b/ar/main.c @@ -336,16 +336,17 @@ del(struct member *m, int argc, char *argv[]) static char * getfname(struct ar_hdr *hdr) { - static char fname[FILENAME_MAX]; + static char fname[SARNAM+1]; size_t i; - char *bp = fname; - for (i = 0; i < sizeof(hdr->ar_name); i++) { - if ((*bp = hdr->ar_name[i]) == ' ') + memcpy(fname, hdr->ar_name, SARNAM); + fname[SARNAM] = '\0'; + + for (i = SARNAM-1; i >= 0; --i) { + if (fname[i] != ' ' && fname[i] != '/') break; - ++bp; + fname[i] = '\0'; } - *bp = '\0'; return fname; } diff --git a/nm/main.c b/nm/main.c @@ -43,14 +43,17 @@ static char * getfname(struct ar_hdr *hdr, char *dst) { char *p; + int i; memcpy(dst, hdr->ar_name, SARNAM); dst[SARNAM] = '\0'; - if ((p = strchr(dst, ' ')) != NULL) - *p = '\0'; - if ((p = strchr(dst, '/')) != NULL) - *p = '\0'; - return (*p == '\0') ? NULL : dst; + + for (i = SARNAM-1; i >= 0; i--) { + if (dst[i] != ' ' && dst[i] != '/') + break; + dst[i] = '\0'; + } + return dst; } static void @@ -68,9 +71,6 @@ ar(char *fname, FILE *fp) if (strncmp(hdr.ar_fmag, ARFMAG, strlen(ARFMAG))) goto corrupted; - if (!getfname(&hdr, member)) - goto corrupted; - siz = 0; sscanf(hdr.ar_size, "%10ld", &siz); if (siz == 0) @@ -86,12 +86,13 @@ ar(char *fname, FILE *fp) } pos += siz; + getfname(&hdr, member); if (object(fname, fp)) { nm(fname, hdr.ar_name, fp); } else { fprintf(stderr, "nm: skipping member %s in archive %s\n", - hdr.ar_name, fname); + member, fname); } fseek(fp, pos, SEEK_SET); }