ref: 83313d4505acea160478ef7bf2c60645e3cec526
parent: 347a2a6c2decb0dc4abcafc4017cfa15d299416a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 23 14:26:04 EDT 2019
[libmach] Add probe method to Objops
--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -45,6 +45,7 @@
};
struct objops {
+ int (*probe)(unsigned char *buf, char **name);
int (*new)(Obj *obj);
int (*read)(Obj *obj, FILE *fp);
int (*addr2line)(Obj *, unsigned long long , char *, int *);
--- a/src/libmach/coff32/coff32.h
+++ b/src/libmach/coff32/coff32.h
@@ -32,6 +32,7 @@
extern int coff32strip(Obj *obj);
extern void coff32del(Obj *obj);
extern int coff32write(Obj *obj, FILE *fp);
+extern int coff32probe(unsigned char *buf, char **name);
extern int coff32xsetidx(int order, long nsyms, Objsymdef *head, FILE *fp);
extern int coff32xgetidx(int order, long *nsyms, Objsymdef **def, FILE *fp);
--- a/src/libmach/libmach.h
+++ b/src/libmach/libmach.h
@@ -30,7 +30,6 @@
/* coff32 functions */
/* TODO: Move this functions to a coff32 files */
-extern int coff32probe(unsigned char *buf, char **name);
extern char *coff32namidx(void);
--- a/src/libmach/objtype.c
+++ b/src/libmach/objtype.c
@@ -4,16 +4,12 @@
#include "libmach.h"
-static int (*funv[])(unsigned char *, char **) = {
- [COFF32] = coff32probe,
-};
-
int
objtype(FILE *fp, char **name)
{
int n, i;
- int (**fn)(unsigned char *, char **);
fpos_t pos;
+ Objops **opsp, *ops;
unsigned char buf[NBYTES];
fgetpos(fp, &pos);
@@ -23,9 +19,8 @@
if (n != 1 || ferror(fp))
return -1;
- for (fn = funv; fn < &funv[NFORMATS]; ++fn) {
- n = (**fn)(buf, name);
- if (n == -1)
+ for (opsp = objops; ops = *opsp; ++opsp) {
+ if ((*ops->probe)(buf, name) < 0)
continue;
return n;
}