scc

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

commit 07ca4e7afc28735ee37d68d438b8e3502bc1e71c
parent eecc7d604fe5c40072f96c00c31a9f8eb8de6714
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 11 Feb 2019 06:37:10 +0000

[libmach] Make uniform the behaviour of for* functions

Diffstat:
Msrc/cmd/nm.c | 10++++++----
Msrc/cmd/ranlib.c | 3+--
Msrc/cmd/size.c | 10++++++----
Msrc/libmach/forsect.c | 7++++---
Msrc/libmach/forsym.c | 6++++--
5 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/cmd/nm.c b/src/cmd/nm.c @@ -198,12 +198,14 @@ nm(char *fname) return; } - if ((t = objtype(fp, NULL)) != -1) + if ((t = objtype(fp, NULL)) != -1) { newobject(fp, t); - else if (archive(fp)) - formember(fp, newmember, NULL); - else + } else if (archive(fp)) { + if (formember(fp, newmember, NULL) < 0) + error("library corrupted"); + } else { error("bad format"); + } if (ferror(fp)) error(strerror(errno)); diff --git a/src/cmd/ranlib.c b/src/cmd/ranlib.c @@ -180,14 +180,13 @@ freehash(void) static int readsyms(FILE *fp) { - /* TODO: Change archive to returns -1 */ if (!archive(fp)) { error("file format not recognized"); return 0; } if (formember(fp, newmember, NULL) < 0) { - error("while traversing archive"); + error("library file corrupted"); return 0; } diff --git a/src/cmd/size.c b/src/cmd/size.c @@ -124,12 +124,14 @@ size(char *fname) return; } - if ((t = objtype(fp, NULL)) != -1) + if ((t = objtype(fp, NULL)) != -1) { newobject(fp, t); - else if (archive(fp)) - formember(fp, newmember, NULL); - else + } else if (archive(fp)) { + if (formember(fp, newmember, NULL) < 0) + error("library corrupted"); + } else { error("bad format"); + } if (ferror(fp)) error(strerror(errno)); diff --git a/src/libmach/forsect.c b/src/libmach/forsect.c @@ -7,11 +7,12 @@ int forsect(Obj *obj, int (*fn)(Objsect *, void *), void *data) { - int i; + int i, r; for (i = 0; i < obj->nsecs; i++) { - if ((*fn)(&obj->sections[i], data)) - return 0; + r = (*fn)(&obj->sections[i], data); + if (r <= 0) + return r; } return 1; diff --git a/src/libmach/forsym.c b/src/libmach/forsym.c @@ -7,11 +7,13 @@ int forsym(Obj *obj, int (*fn)(Objsym *, void *), void *data) { + int r; Objsym *sym; for (sym = obj->head; sym; sym = sym->next) { - if (!(*fn)(sym, data)) - return 0; + r = (*fn)(sym, data); + if (r <= 0) + return r; } return 1; }