32const char* strcasestr(
const char* s1,
const char* s2) {
36 size_t n = strlen(s2);
38 if (!strnicmp(s1++, s2, n))
111 while (*start && isspace(*start))
114 char* end = s + strlen(s) - 1;
116 while (*end && isspace(*end) && end > s) {
148 if (size >= INT_MAX) {
149 n_log(
LOG_ERR,
"size of %zu too big, >INT_MAX for buffer %p", size, buffer);
153 if (!fgets(buffer, (
int)size, stream)) {
207 n_log(
LOG_ERR,
"destination N_STR **str is not NULL (%p), it contain (%s). You must provide an empty destination.", (*to), ((*to) && (*to)->data) ? (*to)->data :
"DATA_IS_NULL");
217 memcpy((*to)->data, from, nboct);
218 (*to)->written = nboct;
230 N_STR* strptr = NULL;
231 size_t length = strlen(src);
261 N_STR* tmpstr = NULL;
262 struct stat filestat;
268 int fd = open(filename, O_RDONLY);
271 n_log(
LOG_ERR,
"Unable to open %s for reading. Errno: %s", filename, strerror(error));
275 if (fstat(fd, &filestat) != 0) {
278 if (error == EOVERFLOW) {
279 n_log(
LOG_ERR,
"%s size is too big ,EOVERFLOW)", filename);
282 n_log(
LOG_ERR,
"Couldn't stat %s. Errno: %s", filename, strerror(error));
290 if ((filestat.st_size + 1) >= (pow(2, 32) - 1)) {
291 n_log(
LOG_ERR,
"file size >= 2GB is not possible yet. %s is %lld oct", filename, filestat.st_size);
295 n_log(
LOG_DEBUG,
"%s file size is: %lld", filename, (
long long unsigned int)filestat.st_size);
297 in = fdopen(fd,
"rb");
299 n_log(
LOG_ERR,
"fdopen failed on %s (fd=%d)", filename, fd);
304 tmpstr =
new_nstr((
size_t)filestat.st_size + 1);
305 __n_assert(tmpstr, fclose(in);
n_log(
LOG_ERR,
"Unable to get a new nstr of %ld octets", filestat.st_size + 1);
return NULL);
307 tmpstr->
written = (size_t)filestat.st_size;
309 if (fread(tmpstr->
data,
sizeof(
char), tmpstr->
written, in) == 0) {
310 n_log(
LOG_ERR,
"Couldn't read %s, fread return 0", filename);
316 n_log(
LOG_ERR,
"There were some errors when reading %s", filename);
338 struct flock out_lock;
347 memset(&out_lock, 0,
sizeof(out_lock));
348 out_lock.l_type = F_WRLCK;
350 fcntl(fileno(out), F_SETLKW, &out_lock);
356 size_t written_to_file = 0;
357 if ((written_to_file = fwrite(str->
data,
sizeof(
char), str->
written, out)) != (
size_t)str->
written) {
358 n_log(
LOG_ERR,
"Couldn't write file, fwrite %d of %d octets", written_to_file, str->
written);
362 n_log(
LOG_ERR,
"There were some errors when writing to %d", fileno(out));
368 memset(&out_lock, 0,
sizeof(out_lock));
369 out_lock.l_type = F_WRLCK;
371 fcntl(fileno(out), F_SETLKW, &out_lock);
390 int fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0600);
392 n_log(
LOG_ERR,
"Couldn't open %s for writing (0600). Errno: %s",
_str(filename), strerror(errno));
397 out = fdopen(fd,
"wb");
399 n_log(
LOG_ERR,
"fdopen failed for %s (fd=%d). Errno: %s",
_str(filename), fd, strerror(errno));
431 Malloc(tmpstr,
char,
sizeof(
int) + end - start + 8);
432 __n_assert(tmpstr,
n_log(
LOG_ERR,
"Unable to Malloc( tmpstr , char , sizeof( int ) + %d - %d )", end, start);
return FALSE);
434 memcpy(tmpstr, s + start, end - start);
437 l = strtol(tmpstr, &endstr, base);
438 if ((errno == ERANGE && l == LONG_MAX) || l > INT_MAX) {
439 n_log(
LOG_ERR,
"OVERFLOW reached when converting %s to int", tmpstr);
443 if ((errno == ERANGE && l == LONG_MIN) || l < INT_MIN) {
444 n_log(
LOG_ERR,
"UNDERFLOW reached when converting %s to int", tmpstr);
448 if (*endstr !=
'\0' && *endstr !=
'\n') {
477 Malloc(tmpstr,
char,
sizeof(
int) + end - start + 8);
478 __n_assert(tmpstr,
n_log(
LOG_ERR,
"Unable to Malloc( tmpstr , char , sizeof( int ) + %d - %d )", end, start);
return FALSE);
480 memcpy(tmpstr, s + start, end - start);
483 l = strtol(tmpstr, &endstr, base);
484 if ((errno == ERANGE && l == LONG_MAX) || l > INT_MAX) {
485 nstrprintf((*infos),
"OVERFLOW reached when converting %s to int", tmpstr);
489 if ((errno == ERANGE && l == LONG_MIN) || l < INT_MIN) {
490 nstrprintf((*infos),
"UNDERFLOW reached when converting %s to int", tmpstr);
494 if (*endstr !=
'\0' && *endstr !=
'\n') {
495 nstrprintf((*infos),
"Impossible conversion for %s", tmpstr);
537 Malloc(tmpstr,
char,
sizeof(
int) + end - start + 8);
538 __n_assert(tmpstr,
n_log(
LOG_ERR,
"Unable to Malloc( tmpstr , char , sizeof( int ) + %d - %d )", end, start);
return FALSE);
540 memcpy(tmpstr, s + start, end - start);
543 l = strtol(tmpstr, &endstr, base);
547 if (tmpstr == endstr) {
548 n_log(
LOG_ERR,
" number : %lu invalid (no digits found, 0 returned)", l);
551 }
else if (error == ERANGE && l == LONG_MIN) {
552 n_log(
LOG_ERR,
" number : %lu invalid (underflow occurred)", l);
555 }
else if (error == ERANGE && l == LONG_MAX) {
556 n_log(
LOG_ERR,
" number : %lu invalid (overflow occurred)", l);
559 }
else if (error == EINVAL)
561 n_log(
LOG_ERR,
" number : %lu invalid (base contains unsupported value)", l);
564 }
else if (error != 0 && l == 0) {
565 n_log(
LOG_ERR,
" number : %lu invalid (unspecified error occurred)", l);
568 }
else if (error == 0 && tmpstr && !*endstr) {
569 n_log(
LOG_DEBUG,
" number : %lu valid (and represents all characters read)", l);
570 }
else if (error == 0 && tmpstr && *endstr != 0) {
571 n_log(
LOG_DEBUG,
" number : %lu valid (but additional characters remain", l);
594 Malloc(tmpstr,
char,
sizeof(
int) + end - start + 8);
595 __n_assert(tmpstr,
n_log(
LOG_ERR,
"Unable to Malloc( tmpstr , char , sizeof( int ) + %d - %d )", end, start);
return FALSE);
597 memcpy(tmpstr, s + start, end - start);
600 l = strtoll(tmpstr, &endstr, base);
604 if (tmpstr == endstr) {
605 n_log(
LOG_ERR,
"number: '%s' invalid (no digits found, 0 returned)", s);
608 }
else if (error == ERANGE && l == LLONG_MIN) {
609 n_log(
LOG_ERR,
"number: '%s' invalid (underflow occurred)", s);
612 }
else if (error == ERANGE && l == LLONG_MAX) {
613 n_log(
LOG_ERR,
"number: 's' invalid (overflow occurred)", s);
616 }
else if (error == EINVAL)
618 n_log(
LOG_ERR,
"number: '%s' invalid (base contains unsupported value)", s);
621 }
else if (error != 0 && l == 0) {
622 n_log(
LOG_ERR,
"number: '%s' invalid (unspecified error occurred)", s);
625 }
else if (error == 0 && tmpstr && !*endstr) {
626 n_log(
LOG_DEBUG,
"number : '%llu' valid (and represents all characters read)", l);
627 }
else if (error == 0 && tmpstr && *endstr != 0) {
628 n_log(
LOG_DEBUG,
" number : '%llu' valid (remaining characters: '%s')", l, s);
671 N_STR* new_str = NULL;
684 n_log(
LOG_ERR,
"Error duplicating N_STR %p -> data", str);
709 while (*iterator <= (
NSTRBYTE)strlen(
string) && isspace(
string[*iterator])) {
710 if (inc < 0 && *iterator == 0) {
715 *iterator = *iterator + (
NSTRBYTE)inc;
717 *iterator = *iterator - (
NSTRBYTE)inc;
721 while (*iterator <= (
NSTRBYTE)strlen(
string) &&
string[*iterator] == toskip) {
722 if (inc < 0 && *iterator == 0) {
727 *iterator = *iterator + (
NSTRBYTE)inc;
729 *iterator = *iterator - (
NSTRBYTE)inc;
733 if (error_flag == 1 || *iterator > (
NSTRBYTE)strlen(
string)) {
758 while (*iterator <= (
NSTRBYTE)strlen(
string) && !isspace(
string[*iterator])) {
759 if (inc < 0 && *iterator == 0) {
764 *iterator = *iterator + (
NSTRBYTE)inc;
766 *iterator = *iterator - (
NSTRBYTE)inc;
770 while (*iterator <= (
NSTRBYTE)strlen(
string) &&
string[*iterator] != toskip) {
771 if (inc < 0 && *iterator == 0) {
776 *iterator = *iterator + (
NSTRBYTE)inc;
778 *iterator = *iterator - (
NSTRBYTE)inc;
783 if (error_flag == 1 || *iterator > (
NSTRBYTE)strlen(
string)) {
798int strup(
char*
string,
char* dest) {
804 for (it = 0; it < (
NSTRBYTE)strlen(
string); it++)
805 dest[it] = (
char)toupper(
string[it]);
817int strlo(
char*
string,
char* dest) {
823 for (it = 0; it < (
NSTRBYTE)strlen(
string); it++)
824 dest[it] = (
char)tolower(
string[it]);
845 while (_it < to_size && from[(*it)] !=
'\0' && from[(*it)] !=
split) {
846 to[_it] = from[(*it)];
851 if (_it == to_size) {
854 n_log(
LOG_DEBUG,
"strcpy_u: not enough space to write %d octet to dest (%d max) , %s: %d \n", _it, to_size, __FILE__, __LINE__);
860 if (from[(*it)] !=
split) {
861 n_log(
LOG_DEBUG,
"strcpy_u: split value not found, written %d octet to dest (%d max) , %s: %d \n", _it, to_size, __FILE__, __LINE__);
874char**
split(
const char* str,
const char* delim,
int empty) {
880 const char* largestring = NULL;
885 size_t sizeDelim = strlen(delim);
888 while ((ptr = strstr(largestring, delim)) != NULL) {
889 sizeStr = (size_t)(ptr - largestring);
890 if (empty == 1 || sizeStr != 0) {
892 tmp = (
char**)realloc(tab,
sizeof(
char*) * sizeTab);
896 Malloc(tab[sizeTab - 1],
char,
sizeof(
char) * (sizeStr + 1));
899 memcpy(tab[sizeTab - 1], largestring, sizeStr);
900 tab[sizeTab - 1][sizeStr] =
'\0';
902 ptr = ptr + sizeDelim;
907 if (strlen(largestring) != 0) {
908 sizeStr = strlen(largestring);
911 tmp = (
char**)realloc(tab,
sizeof(
char*) * sizeTab);
915 Malloc(tab[sizeTab - 1],
char,
sizeof(
char) * (sizeStr + 1));
918 memcpy(tab[sizeTab - 1], largestring, sizeStr);
919 tab[sizeTab - 1][sizeStr] =
'\0';
924 tmp = (
char**)realloc(tab,
sizeof(
char*) * sizeTab);
928 Malloc(tab[sizeTab - 1],
char, (
int)(
sizeof(
char) * 1));
931 tab[sizeTab - 1][0] =
'\0';
937 tmp = (
char**)realloc(tab,
sizeof(
char*) * sizeTab);
940 tab[sizeTab - 1] = NULL;
959 while (split_result[it]) {
990char*
join(
char** splitresult,
char* delim) {
991 size_t delim_length = 0;
993 delim_length = strlen(delim);
994 size_t total_length = 0;
996 while (splitresult[it]) {
998 total_length += strlen(splitresult[it]);
1000 if (delim && splitresult[it + 1])
1001 total_length += delim_length;
1004 char* result = NULL;
1005 Malloc(result,
char, total_length + 1);
1006 size_t position = 0;
1008 while (splitresult[it]) {
1009 size_t copy_size = strlen(splitresult[it]);
1010 memcpy(&result[position], splitresult[it], copy_size);
1011 position += copy_size;
1013 if (delim && splitresult[it + 1]) {
1014 memcpy(&result[position], delim, delim_length);
1015 position += delim_length;
1034 if (resize_flag == 0) {
1036 if (((*dest)->written + size + 1) > (*dest)->length) {
1037 n_log(
LOG_ERR,
"%p to %p: not enough space. Resize forbidden. %lld needed, %lld available", src, (*dest), (*dest)->written + size + 1, (*dest)->length);
1041 n_log(
LOG_ERR,
"%p to %p: not enough space. Resize forbidden. %lld needed, destination is NULL", src, (*dest), size + 1);
1050 if ((*dest)->length < (*dest)->written + size + 1) {
1051 (*dest)->length = (*dest)->written + size + 1;
1052 Reallocz((*dest)->data,
char, (*dest)->written, (*dest)->length);
1056 ptr = (*dest)->data + (*dest)->written;
1057 memcpy(ptr, src, size);
1058 (*dest)->written += size;
1060 (*dest)->data[(*dest)->written] =
'\0';
1076 n_log(
LOG_ERR,
"Could not copy 0 or less (%ld) octet!", size);
1080 return nstrcat_ex(dest, data, size, 1);
1095 NSTRBYTE needed_size = (*written) + src_size + 1;
1098 if ((needed_size >= (*size)) || !(*dest)) {
1103 Reallocz((*dest),
char, (*size), needed_size + additional_padding);
1104 (*size) = needed_size;
1110 ptr = (*dest) + (*written);
1111 memcpy(ptr, src, src_size);
1112 (*written) += src_size;
1113 (*dest)[(*written)] =
'\0';
1150int scan_dir_ex(
const char* dir,
const char* pattern,
LIST* result,
const int recurse,
const int mode) {
1152 struct dirent* entry = NULL;
1153 struct stat statbuf;
1158 if ((dp = opendir(dir)) == NULL) {
1163 N_STR* newname = NULL;
1164 while ((entry = readdir(dp)) != NULL) {
1165 nstrprintf(newname,
"%s/%s", dir, entry->d_name);
1167 if (stat(newname->
data, &statbuf) >= 0) {
1168 if (S_ISDIR(statbuf.st_mode) != 0) {
1169 if (strcmp(
".", entry->d_name) == 0 || strcmp(
"..", entry->d_name) == 0) {
1175 if (recurse != FALSE) {
1176 if (
scan_dir_ex(newname->
data, pattern, result, recurse, mode) != TRUE) {
1177 n_log(
LOG_ERR,
"scan_dir_ex( %s , %s , %p , %d , %d ) returned FALSE !", newname->
data, pattern, result, recurse, mode);
1182 }
else if (S_ISREG(statbuf.st_mode) != 0) {
1185 char* file = strdup(newname->
data);
1189 n_log(
LOG_ERR,
"Error adding %s/%s to list", dir, entry->d_name);
1191 }
else if (mode == 1) {
1211int wildmat(
register const char* text,
register const char* p) {
1212 register int last = 0;
1213 register int matched = 0;
1214 register int reverse = 0;
1216 for (; *p; text++, p++) {
1217 if (*text ==
'\0' && *p !=
'*')
1239 if ((matched =
wildmat(text++, p)) != FALSE)
1248 if (p[1] ==
']' || p[1] ==
'-')
1251 for (last = *p; *++p && *p !=
']'; last = *p)
1253 if (*p ==
'-' && p[1] !=
']'
1254 ? *text <= *++p && *text >= last
1257 if (matched == reverse)
1262#ifdef WILDMAT_MATCH_TAR_PATTERN
1266 return *text ==
'\0';
1277 register int matched;
1278 register int reverse;
1280 for (; *p; text++, p++) {
1281 if (*text ==
'\0' && *p !=
'*')
1289 if (toupper(*text) != toupper(*p))
1312 if (p[1] ==
']' || p[1] ==
'-')
1313 if (toupper(*++p) == toupper(*text))
1315 for (last = toupper(*p); *++p && *p !=
']'; last = toupper(*p))
1316 if (*p ==
'-' && p[1] !=
']'
1317 ? toupper(*text) <= toupper(*++p) && toupper(*text) >= last
1318 : toupper(*text) == toupper(*p))
1320 if (matched == reverse)
1325#ifdef WILDMAT_MATCH_TAR_PATTERN
1329 return *text ==
'\0';
1341char*
str_replace(
const char*
string,
const char* substr,
const char* replacement) {
1343 char* newstr = NULL;
1344 char* oldstr = NULL;
1348 if (substr == NULL || replacement == NULL)
1349 return strdup(
string);
1350 newstr = strdup(
string);
1352 while ((tok = strstr(head, substr))) {
1354 Malloc(newstr,
char, strlen(oldstr) - strlen(substr) + strlen(replacement) + 8);
1356 if (newstr == NULL) {
1360 memcpy(newstr, oldstr, (
size_t)(tok - oldstr));
1361 memcpy(newstr + (tok - oldstr), replacement, strlen(replacement));
1362 memcpy(newstr + (tok - oldstr) + strlen(replacement), tok + strlen(substr), strlen(oldstr) - strlen(substr) - (
size_t)(tok - oldstr));
1363 memset(newstr + strlen(oldstr) - strlen(substr) + strlen(replacement), 0, 1);
1365 head = newstr + (tok - oldstr) + strlen(replacement);
1385 for (it = 0; it < string_len; it++) {
1387 while (mask_it < masklen && mask[mask_it] !=
'\0') {
1388 if (
string[it] == mask[mask_it])
1389 string[it] = replacement;
1404 return str_sanitize_ex(
string, strlen(
string), mask, strlen(mask), replacement);
1443N_STR* nstrprintf_ex(
N_STR** nstr_var,
const char* format, ...) {
1448 int needed_size = 0;
1451 va_start(args, format);
1452 va_copy(args_copy, args);
1453 needed_size = vsnprintf(NULL, 0, format, args);
1456 if (needed_size < 0) {
1457 n_log(
LOG_ERR,
"there was an error while computing the new size according to format \"%s\" for N_STR %p", format, (*nstr_var));
1461 size_t needed = (size_t)(needed_size + 1);
1466 }
else if (needed > (*nstr_var)->length) {
1468 n_log(
LOG_ERR,
"could not resize N_STR %p to size %zu", (*nstr_var), needed);
1474 vsnprintf((*nstr_var)->data, needed, format, args_copy);
1477 (*nstr_var)->written = (size_t)needed_size;
1488N_STR* nstrprintf_cat_ex(
N_STR** nstr_var,
const char* format, ...) {
1493 int needed_size = 0;
1497 va_start(args, format);
1498 va_copy(args_copy, args);
1499 (*nstr_var) =
nstrprintf((*nstr_var), format, args_copy);
1506 va_start(args, format);
1507 va_copy(args_copy, args);
1508 needed_size = vsnprintf(NULL, 0, format, args);
1511 if (needed_size < 0) {
1512 n_log(
LOG_ERR,
"there was an error while computing the new size according to format \"%s\" for N_STR %p", format, (*nstr_var));
1517 size_t needed = (size_t)(needed_size + 1);
1518 size_t total_needed = (*nstr_var)->written + needed;
1521 if (total_needed > (*nstr_var)->length) {
1526 vsnprintf((*nstr_var)->data + (*nstr_var)->written, needed, format, args_copy);
1527 (*nstr_var)->written += (size_t)needed_size;
#define FreeNoLog(__ptr)
Free Handler without log.
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define _str(__PTR)
define true
#define Reallocz(__ptr, __struct, __old_size, __size)
Realloc + zero new memory zone Handler to get errors.
#define Free(__ptr)
Free Handler to get errors.
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
Structure of a generic LIST container.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
size_t written
size of the written data inside the string
size_t length
length of string (in case we wanna keep information after the 0 end of string value)
int str_to_long_long(const char *s, long long int *i, const int base)
Helper for string to integer.
int strcpy_u(char *from, char *to, NSTRBYTE to_size, char split, NSTRBYTE *it)
Copy from start to dest until from[ iterator ] == split.
char * trim_nocopy(char *s)
trim and zero end the string, WARNING: keep and original pointer to delete the string correctly
void free_nstr_ptr(void *ptr)
Free a N_STR pointer structure.
size_t NSTRBYTE
N_STR base unit.
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
int split_count(char **split_result)
Count split elements.
int str_sanitize_ex(char *string, const NSTRBYTE string_len, const char *mask, const NSTRBYTE masklen, const char replacement)
clean a string by replacing evil characteres
int nstr_to_file(N_STR *str, char *filename)
Write a N_STR content into a file.
int scan_dir_ex(const char *dir, const char *pattern, LIST *result, const int recurse, const int mode)
Scan a list of directory and return a list of char *file.
int str_to_long_long_ex(const char *s, NSTRBYTE start, NSTRBYTE end, long long int *i, const int base)
Helper for string[start to end] to long long integer.
N_STR * nstrdup(N_STR *str)
Duplicate a N_STR.
int write_and_fit(char **dest, NSTRBYTE *size, NSTRBYTE *written, const char *src)
concatenate a copy of src of size strlen( src ) to dest, starting at dest[ written ],...
int str_to_int_ex(const char *s, NSTRBYTE start, NSTRBYTE end, int *i, const int base)
Helper for string[start to end] to integer.
int str_to_int_nolog(const char *s, NSTRBYTE start, NSTRBYTE end, int *i, const int base, N_STR **infos)
Helper for string[start to end] to integer.
int resize_nstr(N_STR *nstr, size_t size)
reallocate a nstr internal buffer.
N_STR * char_to_nstr(const char *src)
Convert a char into a N_STR, short version.
char * nfgets(char *buffer, NSTRBYTE size, FILE *stream)
try to fgets
int skipw(char *string, char toskip, NSTRBYTE *iterator, int inc)
skip while 'toskip' occurence is found from 'iterator' to the next non 'toskip' position.
#define WILDMAT_ABORT
Abort code to sped up pattern matching.
int empty_nstr(N_STR *nstr)
empty a N_STR string
int wildmatcase(register const char *text, register const char *p)
Written by Rich Salz rsalz at osf.org, refurbished by me.
#define WILDMAT_NEGATE_CLASS
What character marks an inverted character class?
N_STR * new_nstr(NSTRBYTE size)
create a new N_STR string
char * str_replace(const char *string, const char *substr, const char *replacement)
Replace "substr" by "replacement" inside string taken from http://coding.debuntu.org/c-implementing-s...
#define nstrprintf(__nstr_var, __format,...)
Macro to quickly allocate and sprintf to N_STR.
N_STR * nstrcat_bytes_ex(N_STR **dest, void *data, NSTRBYTE size)
Append data into N_STR using internal N_STR size and cursor position.
int scan_dir(const char *dir, LIST *result, const int recurse)
Scan a list of directory and return a list of char *file.
int str_sanitize(char *string, const char *mask, const char replacement)
clean a string by replacing evil characteres
char ** split(const char *str, const char *delim, int empty)
split the strings into a an array of char *pointer , ended by a NULL one.
int strup(char *string, char *dest)
Upper case a string.
int wildmat(register const char *text, register const char *p)
Written by Rich Salz rsalz at osf.org, refurbished by me.
int free_nstr_nolog(N_STR **ptr)
Free a N_STR structure and set the pointer to NULL.
int str_to_long(const char *s, long int *i, const int base)
Helper for string to integer.
int char_to_nstr_ex(const char *from, NSTRBYTE nboct, N_STR **to)
Convert a char into a N_STR, extended version.
N_STR * char_to_nstr_nocopy(char *src)
Convert a char into a N_STR, direct use of linked source pointer.
int _free_nstr(N_STR **ptr)
Free a N_STR structure and set the pointer to NULL.
int write_and_fit_ex(char **dest, NSTRBYTE *size, NSTRBYTE *written, const char *src, NSTRBYTE src_size, NSTRBYTE additional_padding)
concatenate a copy of src of size src_size to dest, starting at dest[ written ], updating written and...
char * join(char **splitresult, char *delim)
join the array into a string
N_STR * file_to_nstr(char *filename)
Load a whole file into a N_STR.
int free_split_result(char ***tab)
Free a split result allocated array.
void free_nstr_ptr_nolog(void *ptr)
Free a N_STR pointer structure.
int str_to_int(const char *s, int *i, const int base)
Helper for string to integer.
int skipu(char *string, char toskip, NSTRBYTE *iterator, int inc)
skip until 'toskip' occurence is found from 'iterator' to the next 'toskip' value.
char * trim(char *s)
trim and put a \0 at the end, return new char *
int strlo(char *string, char *dest)
Upper case a string.
int nstr_to_fd(N_STR *str, FILE *out, int lock)
Write a N_STR content into a file.
int str_to_long_ex(const char *s, NSTRBYTE start, NSTRBYTE end, long int *i, const int base)
Helper for string[start to end] to long integer.
A box including a string and his lenght.
Common headers and low-level functions & define.
N_STR and string function declaration.