scc

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

commit 8eb6511a9d0aa401cbb40bad46473e33c9bb2888
parent e0784393d9b7693c12ed0b5f8bbc51d949503fd4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  4 Jan 2019 17:13:57 +0000

[nm] Fix libraries dealing

Diffstat:
Minclude/scc/scc/mach.h | 2+-
Msrc/libmach/armember.c | 14+++++++-------
Msrc/libmach/artraverse.c | 11++++-------
Msrc/nm/nm.c | 2+-
4 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -18,7 +18,7 @@ struct object { }; extern int archive(FILE *fp); -extern int armember(FILE *fp, char *member); +extern long armember(FILE *fp, char *member); extern int artraverse(FILE *fp, int (*fn)(FILE *, char *, void *), diff --git a/src/libmach/armember.c b/src/libmach/armember.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <scc/ar.h> @@ -21,20 +22,19 @@ getfname(struct ar_hdr *hdr, char *dst) return dst; } -int +long armember(FILE *fp, char *member) { - struct ar_hdr hdr; - long siz; + struct ar_hdr hdr; + long siz; - if (fread(&hdr, sizeof(hdr), 1, fp) != 1) + if (fread(&hdr, sizeof(hdr), 1, fp) != 1) return (feof(fp)) ? 0 : -1; if (strncmp(hdr.ar_fmag, ARFMAG, sizeof(hdr.ar_fmag))) return -1; - siz = 0; - sscanf(hdr.ar_size, "%10ld", &siz); + siz = strtol(hdr.ar_size, NULL, 0); if (siz & 1) siz++; if (siz == 0) @@ -42,5 +42,5 @@ armember(FILE *fp, char *member) getfname(&hdr, member); - return 0; + return sizeof(hdr) + siz; } diff --git a/src/libmach/artraverse.c b/src/libmach/artraverse.c @@ -14,16 +14,13 @@ artraverse(FILE *fp, int (*fn)(FILE *, char *, void *), void *data) for (;;) { fgetpos(fp, &pos); - if ((off = armember(fp, name)) < 0) - return -1; - r = !(*fn)(fp, name, data); + if ((off = armember(fp, name)) <= 0) + return off; + r = (*fn)(fp, name, data); if (!r) return r; fsetpos(fp, &pos); - fseek(fp, off, SEEK_SET); - - if (off == 0) - return 0; + fseek(fp, off, SEEK_CUR); } } diff --git a/src/nm/nm.c b/src/nm/nm.c @@ -159,7 +159,7 @@ newmember(FILE *fp, char *name, void *data) if ((t = objtest(fp, NULL)) != -1) newobject(fp, t); - return 0; + return 1; } static void