scc

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

objtype.c (426B)


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