ref: 62b5f13a7e487d4cadb1c82ca7642e34dfcbb512
parent: b709b8fa6bd37944b2e0a53bef8df2fca5e9519e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Feb 11 01:37:10 EST 2019
[libmach] Make uniform the behaviour of for* functions
--- a/src/cmd/nm.c
+++ b/src/cmd/nm.c
@@ -198,12 +198,14 @@
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));
--- a/src/cmd/ranlib.c
+++ b/src/cmd/ranlib.c
@@ -180,7 +180,6 @@
static int
readsyms(FILE *fp)
{
- /* TODO: Change archive to returns -1 */
if (!archive(fp)) {
error("file format not recognized");
return 0;
@@ -187,7 +186,7 @@
}
if (formember(fp, newmember, NULL) < 0) {
- error("while traversing archive");
+ error("library file corrupted");
return 0;
}
--- a/src/cmd/size.c
+++ b/src/cmd/size.c
@@ -124,12 +124,14 @@
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));
--- 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;
--- 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;
}