]> Devoid-pointer.net GitWeb - libHPCS.git/commitdiff
Provide alloc() and free() functions to simplify memory deallocation and
authorMichal Malý <madcatxster@devoid-pointer.net>
Sun, 29 Jun 2014 23:52:32 +0000 (01:52 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Sun, 29 Jun 2014 23:52:32 +0000 (01:52 +0200)
prevent usage of different allocators.

libhpcs.c
libhpcs.h

index e6f4e27e2f47dc5a79439432f43bcbbef19661b4..880f4ebfc4b468842eef3b33a1f8f0c70b98c167 100644 (file)
--- a/libhpcs.c
+++ b/libhpcs.c
@@ -4,6 +4,11 @@
 #include <stdlib.h>
 #include <string.h>
 
+struct HPCS_MeasuredData* hpcs_alloc()
+{
+       return malloc(sizeof(struct HPCS_MeasuredData));
+}
+
 char* hpcs_error_to_string(const enum HPCS_RetCode err)
 {
        char* msg;
@@ -36,6 +41,21 @@ char* hpcs_error_to_string(const enum HPCS_RetCode err)
        }
 }
 
+void hpcs_free(struct HPCS_MeasuredData* const mdata)
+{
+       if (mdata == NULL)
+               return;
+       free(mdata->file_description);
+       free(mdata->sample_info);
+       free(mdata->operator_name);
+       free(mdata->method_name);
+       free(mdata->cs_ver);
+       free(mdata->cs_rev);
+       free(mdata->y_units);
+       free(mdata->data);
+       free(mdata);
+}
+
 enum HPCS_RetCode hpcs_read_file(const char* filename, struct HPCS_MeasuredData* mdata)
 {
        FILE* datafile;
index 42db2c43bf7f681b26c342c7c7d836953b898cbc..9b794512c700a35d35c1c4cd3c96513b0682be09 100644 (file)
--- a/libhpcs.h
+++ b/libhpcs.h
@@ -54,11 +54,15 @@ struct HPCS_MeasuredData {
 };
 
 #ifdef __WIN32__
-__declspec(dllexport) enum HPCS_RetCode __cdecl hpcs_read_file(const char* const filename, struct HPCS_MeasuredData* mdata);
+__declspec(dllexport) struct HPCS_MeasuredData* __cdecl hpcs_alloc();
+__declspec(dllexport) void __cdecl hpcs_free(struct HPCS_MeasuredData* const mdata);
 __declspec(dllexport) char* __cdecl hpcs_error_to_string(const enum HPCS_RetCode);
+__declspec(dllexport) enum HPCS_RetCode __cdecl hpcs_read_file(const char* const filename, struct HPCS_MeasuredData* mdata);
 #else
-enum HPCS_RetCode hpcs_read_file(const char* const filename, struct HPCS_MeasuredData* mdata);
+struct HPCS_MeasuredData* hpcs_alloc();
+void hpcs_free(struct HPCS_MeasuredData* const mdata);
 char* hpcs_error_to_string(const enum HPCS_RetCode);
+enum HPCS_RetCode hpcs_read_file(const char* const filename, struct HPCS_MeasuredData* mdata);
 #endif
 
 #ifdef __cplusplus