scc

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

objnew.c (540B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 #include <scc/mach.h>
      6 
      7 #include "libmach.h"
      8 
      9 static int (*funv[])(Obj *) = {
     10 	[COFF32] = coff32new,
     11 };
     12 
     13 Obj *
     14 objnew(int type)
     15 {
     16 	Obj *obj;
     17 	int fmt;
     18 
     19 	fmt = FORMAT(type);
     20 	if (fmt >= NFORMATS)
     21 		return NULL;
     22 
     23 	if ((obj = malloc(sizeof(*obj))) == NULL)
     24 		return NULL;
     25 
     26 	obj->type = type;
     27 	obj->syms = NULL;
     28 	obj->secs = NULL;
     29 	obj->nsyms = 0;
     30 	obj->nsecs = 0;
     31 	memset(obj->htab, 0, sizeof(obj->htab));
     32 
     33 	if ((*funv[fmt])(obj) < 0) {
     34 		free(obj);
     35 		return NULL;
     36 	}
     37 
     38 	return obj;
     39 }