scc

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

objtype.c (518B)


      1 #include <stdio.h>
      2 
      3 #include <scc/mach.h>
      4 
      5 #include "libmach.h"
      6 
      7 static int (*funv[])(unsigned char *, char **) = {
      8 	[COFF32] = coff32probe,
      9 };
     10 
     11 int
     12 objtype(FILE *fp, char **name)
     13 {
     14 	int n, i;
     15 	int (**fn)(unsigned char *, char **);
     16 	fpos_t pos;
     17 	unsigned char buf[NBYTES];
     18 
     19 	fgetpos(fp, &pos);
     20 	n = fread(buf, NBYTES, 1, fp);
     21 	fsetpos(fp, &pos);
     22 
     23 	if (n != 1 || ferror(fp))
     24 		return -1;
     25 
     26 	for (fn = funv; fn < &funv[NFORMATS]; ++fn) {
     27 		n = (**fn)(buf, name);
     28 		if (n == -1)
     29 			continue;
     30 		return n;
     31 	}
     32 
     33 	return -1;
     34 }