Begin the implementation of a type.

This commit is contained in:
2018-03-31 15:54:59 -07:00
parent c5fa68fdf5
commit 35fc0e7fd1
3 changed files with 69 additions and 1 deletions

28
src/type.c Normal file
View File

@@ -0,0 +1,28 @@
#include "type.h"
#include "util.h"
#include <stdlib.h>
void _libab_type_free(void* type) {
free(((libab_type*) type)->name);
}
libab_result libab_type_create(libab_ref* ref, const char* name) {
libab_type* type;
libab_result result = LIBAB_SUCCESS;
if((type = malloc(sizeof(*type)))) {
result = libab_copy_string(&type->name, name);
} else {
result = LIBAB_MALLOC;
}
if(result == LIBAB_SUCCESS) {
result = libab_ref_new(ref, type, _libab_type_free);
if(result != LIBAB_SUCCESS) free(type->name);
}
if(result != LIBAB_SUCCESS) {
free(type);
}
return result;
}