
3 changed files with 92 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||||
|
#include "libc99.h" |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
|
||||
|
Test_struct1* new_test_struct(int c_int, Test_enum c_enum, const char* c_str) |
||||
|
{ |
||||
|
Test_struct1* result = calloc(1, sizeof(Test_struct1)); |
||||
|
if (result) { |
||||
|
result->c_int = c_int; |
||||
|
result->c_enum = c_enum; |
||||
|
if (c_str) { |
||||
|
result->c_str = strdup(c_str); |
||||
|
if (result->c_str == NULL) { |
||||
|
free_test_struct(result); |
||||
|
return NULL; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
void free_test_struct(Test_struct1* c_struct) |
||||
|
{ |
||||
|
if (c_struct) { |
||||
|
free(c_struct->c_str); |
||||
|
free(c_struct); |
||||
|
} |
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
// We are testing wrappers for the c-datatypes:
|
||||
|
// * integral e.g (int) here
|
||||
|
// * enum
|
||||
|
// * c-string
|
||||
|
// * struct
|
||||
|
// Those are all considered POD-types
|
||||
|
#ifdef __cplusplus |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
typedef enum |
||||
|
{ |
||||
|
ONE, |
||||
|
TWO, |
||||
|
THREE |
||||
|
} Test_enum; |
||||
|
|
||||
|
typedef struct { |
||||
|
int c_int; |
||||
|
Test_enum c_enum; |
||||
|
char* c_str; |
||||
|
} Test_struct1; |
||||
|
|
||||
|
typedef struct { |
||||
|
int c_int; |
||||
|
Test_enum c_enum; |
||||
|
char* c_str; |
||||
|
Test_struct1* c_struct1; |
||||
|
} Test_struct2; |
||||
|
|
||||
|
|
||||
|
Test_struct1* new_test_struct(int c_int, Test_enum c_enum, const char* c_str); |
||||
|
|
||||
|
void free_test_struct(Test_struct1* c_struct); |
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
@ -0,0 +1,27 @@ |
|||||
|
LIB_STATIC=libc99.a |
||||
|
LIB_DYN=libc99.so |
||||
|
|
||||
|
CFLAGS+=-std=c99 -g -UNDEBUG |
||||
|
|
||||
|
SRCS+=$(wildcard *.c) |
||||
|
OBJS_C+=$(SRCS:.c=.o) |
||||
|
|
||||
|
.PHONY: all lib_static lib_dyn clean |
||||
|
|
||||
|
all: lib_static lib_dyn |
||||
|
|
||||
|
lib_static: $(LIB_STATIC) |
||||
|
|
||||
|
lib_dyn: $(LIB_DYN) |
||||
|
|
||||
|
$(LIB_STATIC): $(OBJS_C) |
||||
|
$(AR) -rc $@ $^ |
||||
|
|
||||
|
$(LIB_DYN): $(OBJS_C) |
||||
|
$(CC) $(CFLAGS) -shared -o $@ $^ |
||||
|
|
||||
|
clean: |
||||
|
rm -f $(LIB_STATIC) |
||||
|
rm -f $(LIB_DYN) |
||||
|
rm -f $(OBJS_C) |
||||
|
|
Loading…
Reference in new issue