1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <errno.h>56#include <scc/mach.h>78#include "libmach.h"910#include "elf/fun.h"11#include "coff32/fun.h"1213static int (*ops[NFORMATS])(Obj *, int) = {14 [COFF32] = coff32new,15 [ELF] = elfnew,16};1718Obj *19newobj(int type)20{21 Obj *obj;22 int fmt;2324 fmt = FORMAT(type);25 if (fmt >= NFORMATS) {26 errno = ERANGE;27 return NULL;28 }2930 if ((obj = malloc(sizeof(*obj))) == NULL)31 return NULL;3233 obj->type = type;34 obj->next = NULL;35 if ((*ops[fmt])(obj, type) < 0) {36 free(obj);37 return NULL;38 }3940 return obj;41}