added consuming string conversion functions, addded pkg-config and install rules to meson
Minclude/cutils/dyn_string.h
| @@ -32,7 +32,9 @@ size_t* string_find_char(const String* haystack, const char needle); | |||
|---|---|---|---|
| 32 | 32 | ||
| 33 | 33 | bool string_concat(String* string, const String* other); | |
| 34 | 34 | String* from_cstring(const char* cstring); | |
| 35 | + | String* from_cstring_del(char* cstring); | |
| 35 | 36 | char* to_cstring(const String* string); | |
| 37 | + | char* to_cstring_del(String* string); | |
| 36 | 38 | ||
| 37 | 39 | ||
| 38 | 40 | #endif /* DYN_STRING_H */ | |
Minclude/meson.build
| @@ -1 +1,2 @@ | |||
|---|---|---|---|
| 1 | 1 | inc = include_directories('.') | |
| 2 | + | install_headers('cutils/cutils.h', 'cutils/dyn_string.h', 'cutils/vector.h', 'cutils/misc.h', subdir: 'cutils') | |
Mmeson.build
| @@ -5,3 +5,10 @@ CFLAGS = ['-std=c89', '-fstrict-aliasing', '-fPIC'] + WARNINGS | |||
|---|---|---|---|
| 5 | 5 | ||
| 6 | 6 | subdir('include') | |
| 7 | 7 | subdir('src') | |
| 8 | + | ||
| 9 | + | ||
| 10 | + | pkg = import('pkgconfig') | |
| 11 | + | libs = 'cutils' | |
| 12 | + | headers = 'include' | |
| 13 | + | ||
| 14 | + | pkg.generate(libraries : cutils_lib, subdirs : headers, version : '1.0', name : 'libcutils', filebase : 'cutils', description : 'Collection of some portable helper function and data structures in C89.') | |
Msrc/dyn_string.c
| @@ -119,6 +119,13 @@ String* from_cstring(const char* cstring) | |||
|---|---|---|---|
| 119 | 119 | ||
| 120 | 120 | } | |
| 121 | 121 | ||
| 122 | + | String* from_cstring_del(char* cstring) | |
| 123 | + | { | |
| 124 | + | String* ret = from_cstring(cstring); | |
| 125 | + | free(cstring); | |
| 126 | + | return ret; | |
| 127 | + | } | |
| 128 | + | ||
| 122 | 129 | char* to_cstring(const String* string) | |
| 123 | 130 | { | |
| 124 | 131 | char* cstring = malloc(string->length+1); | |
| @@ -127,3 +134,10 @@ char* to_cstring(const String* string) | |||
|---|---|---|---|
| 127 | 134 | ||
| 128 | 135 | return cstring; | |
| 129 | 136 | } | |
| 137 | + | ||
| 138 | + | char* to_cstring_del(String* string) | |
| 139 | + | { | |
| 140 | + | char* ret = to_cstring(string); | |
| 141 | + | delete_string(string); | |
| 142 | + | return ret; | |
| 143 | + | } | |
Msrc/meson.build
| @@ -1,7 +1,8 @@ | |||
|---|---|---|---|
| 1 | 1 | src = ['vector.c', 'dyn_string.c', 'misc.c'] | |
| 2 | 2 | srctest = src + ['test.c'] | |
| 3 | 3 | ||
| 4 | - | lib = shared_library('cutils', src, include_directories : inc) | |
| 5 | - | cutils_dep = declare_dependency(link_with : lib, include_directories : inc) | |
| 4 | + | cutils_lib = library('cutils', src, include_directories : inc, install: true) | |
| 6 | 5 | ||
| 7 | - | executable('test_cutils', srctest, include_directories : inc, c_args: CFLAGS ) | |
| 6 | + | cutils_dep = declare_dependency(link_with : cutils_lib, include_directories : inc) | |
| 7 | + | ||
| 8 | + | executable('test_cutils', srctest, include_directories : inc, c_args: CFLAGS ) | |