scc

A fork of https://git.simple-cc.org/scc/ for Qute

git clone https://git.8pit.net/scc.git

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