scc

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

coff32probe.c (499B)


      1 #include <stdio.h>
      2 
      3 #include <scc/mach.h>
      4 
      5 #include "../libmach.h"
      6 #include "coff32.h"
      7 
      8 static struct arch archs[] = {
      9 	"coff32-i386", "\x4c\x01", OBJ(COFF32, ARCH386, LITTLE_ENDIAN),
     10 	"coff32-z80", "\x5a\x80", OBJ(COFF32, ARCHZ80, LITTLE_ENDIAN),
     11 	NULL,
     12 };
     13 
     14 int
     15 coff32probe(unsigned char *buf, char **name)
     16 {
     17 	struct arch *ap;
     18 
     19 	for (ap = archs; ap->name; ap++) {
     20 		if (ap->magic[0] == buf[0] && ap->magic[1] == buf[1]) {
     21 			if (name)
     22 				*name = ap->name;
     23 			return ap->type;
     24 		}
     25 	}
     26 	return -1;
     27 }