diff options
author | lantw44 <lantw44@gmail.com> | 2012-08-30 00:05:33 +0800 |
---|---|---|
committer | lantw44 <lantw44@gmail.com> | 2012-08-30 00:05:33 +0800 |
commit | 516f31006b9c1b47f85b31deef28b78276f2c4bb (patch) | |
tree | 78c1971b2ca1f48dea81c18c3f31561e93319aba /l4darr/d1arrstr.c | |
download | l4basic-516f31006b9c1b47f85b31deef28b78276f2c4bb.tar l4basic-516f31006b9c1b47f85b31deef28b78276f2c4bb.tar.gz l4basic-516f31006b9c1b47f85b31deef28b78276f2c4bb.tar.bz2 l4basic-516f31006b9c1b47f85b31deef28b78276f2c4bb.tar.lz l4basic-516f31006b9c1b47f85b31deef28b78276f2c4bb.tar.xz l4basic-516f31006b9c1b47f85b31deef28b78276f2c4bb.tar.zst l4basic-516f31006b9c1b47f85b31deef28b78276f2c4bb.zip |
Initial commit - copy project files
Diffstat (limited to 'l4darr/d1arrstr.c')
-rw-r--r-- | l4darr/d1arrstr.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/l4darr/d1arrstr.c b/l4darr/d1arrstr.c new file mode 100644 index 0000000..212760e --- /dev/null +++ b/l4darr/d1arrstr.c @@ -0,0 +1,43 @@ +#include <string.h> +#include <l4darr.h> + +L4DA* l4da_dup(const L4DA* arr){ + L4DA* newarr = l4da_create_setmax( + l4da_itemsize(arr), l4da_getlen(arr), l4da_getmax(arr)); + if(newarr == NULL){ + return NULL; + } + memcpy(newarr->arr_data, arr->arr_data, + l4da_getlen(arr) * l4da_itemsize(arr)); + return newarr; +} + +int l4da_combine(L4DA* arr, const L4DA* att){ + if(l4da_itemsize(arr) != l4da_itemsize(att)){ + return -2; + } + if(l4da_setlen(arr, l4da_getlen(arr) + l4da_getlen(att)) < 0){ + return -1; + } + memcpy(l4da_vp(arr, l4da_getlen(arr)), att->arr_data, + l4da_getlen(att) * l4da_itemsize(att)); + return 0; +} + +L4DA* l4da_filereadline_delim(FILE* infile, int chr){ + L4DA* newarr = l4da_create(1, 0); + if(newarr == NULL){ + return NULL; + } + int c; + char towrite; + do{ + c = getc(infile); + towrite = c; + if(l4da_pushback(newarr, (void*)&towrite) < 0){ + l4da_free(newarr); + return NULL; + } + }while(c != chr); + return newarr; +} |