shithub: scc

ref: 8105290a1e8cc4bda9b9bb7e9583b9282fcb1cb1
dir: /src/libmach/objtype.c/

View raw version
#include <stdio.h>

#include <scc/mach.h>

#include "libmach.h"

int
objtype(FILE *fp, char **name)
{
	int n, i;
	fpos_t pos;
	Objops **opsp, *ops;
	unsigned char buf[NBYTES];

	fgetpos(fp, &pos);
	n = fread(buf, NBYTES, 1, fp);
	fsetpos(fp, &pos);

	if (n != 1 || ferror(fp))
		return -1;

	for (opsp = objops; ops = *opsp; ++opsp) {
		if ((*ops->probe)(buf, name) < 0)
			continue;
		return opsp - objops;
	}

	return -1;
}