Backport from xs.

This commit is contained in:
default 2022-11-24 08:47:02 +01:00
parent 1941d00650
commit f2528c6c52
5 changed files with 9 additions and 6 deletions

5
xs.h
View file

@ -34,6 +34,9 @@ typedef char d_char;
/* auto-destroyable strings */ /* auto-destroyable strings */
#define xs __attribute__ ((__cleanup__ (_xs_destroy))) d_char #define xs __attribute__ ((__cleanup__ (_xs_destroy))) d_char
/* not really all, just very much */
#define XS_ALL 0xfffffff
void *xs_free(void *ptr); void *xs_free(void *ptr);
void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func); void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func);
#define xs_realloc(ptr, size) _xs_realloc(ptr, size, __FILE__, __LINE__, __FUNCTION__) #define xs_realloc(ptr, size) _xs_realloc(ptr, size, __FILE__, __LINE__, __FUNCTION__)
@ -74,7 +77,7 @@ d_char *xs_list_pop(d_char *list, char **data);
int xs_list_in(char *list, const char *val); int xs_list_in(char *list, const char *val);
d_char *xs_join(char *list, const char *sep); d_char *xs_join(char *list, const char *sep);
d_char *xs_split_n(const char *str, const char *sep, int times); d_char *xs_split_n(const char *str, const char *sep, int times);
#define xs_split(str, sep) xs_split_n(str, sep, 0xfffffff) #define xs_split(str, sep) xs_split_n(str, sep, XS_ALL)
d_char *xs_dict_new(void); d_char *xs_dict_new(void);
d_char *xs_dict_append_m(d_char *dict, const char *key, const char *mem, int dsz); d_char *xs_dict_append_m(d_char *dict, const char *key, const char *mem, int dsz);
#define xs_dict_append(dict, key, data) xs_dict_append_m(dict, key, data, xs_size(data)) #define xs_dict_append(dict, key, data) xs_dict_append_m(dict, key, data, xs_size(data))

View file

@ -5,7 +5,7 @@
#define _XS_GLOB_H #define _XS_GLOB_H
d_char *xs_glob_n(const char *spec, int basename, int reverse, int max); d_char *xs_glob_n(const char *spec, int basename, int reverse, int max);
#define xs_glob(spec, basename, reverse) xs_glob_n(spec, basename, reverse, 0xfffffff) #define xs_glob(spec, basename, reverse) xs_glob_n(spec, basename, reverse, XS_ALL)
#ifdef XS_IMPLEMENTATION #ifdef XS_IMPLEMENTATION

View file

@ -79,7 +79,7 @@ d_char *xs_read(FILE *f, int *sz)
d_char *xs_readall(FILE *f) d_char *xs_readall(FILE *f)
/* reads the rest of the file into a string */ /* reads the rest of the file into a string */
{ {
int size = 0xfffffff; int size = XS_ALL;
return xs_read(f, &size); return xs_read(f, &size);
} }

View file

@ -5,9 +5,9 @@
#define _XS_REGEX_H #define _XS_REGEX_H
d_char *xs_regex_split_n(const char *str, const char *rx, int count); d_char *xs_regex_split_n(const char *str, const char *rx, int count);
#define xs_regex_split(str, rx) xs_regex_split_n(str, rx, 0xfffffff) #define xs_regex_split(str, rx) xs_regex_split_n(str, rx, XS_ALL)
d_char *xs_regex_match_n(const char *str, const char *rx, int count); d_char *xs_regex_match_n(const char *str, const char *rx, int count);
#define xs_regex_match(str, rx) xs_regex_match_n(str, rx, 0xfffffff) #define xs_regex_match(str, rx) xs_regex_match_n(str, rx, XS_ALL)
#ifdef XS_IMPLEMENTATION #ifdef XS_IMPLEMENTATION

View file

@ -1 +1 @@
/* a78beb97d364ff31cbaa504e275118afeaea7a59 */ /* 2c01845d968c01c84aa52ff00ed029d9277c2d9c */