From: Daan De Meyer Date: Mon, 5 May 2025 19:50:56 +0000 (+0200) Subject: alloc-util: Move strdupa_safe() and strndupa_safe() to string-util.h X-Git-Tag: v258-rc1~687 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02207b54d5edceb11fc1deea7553ff83ccb5acf6;p=thirdparty%2Fsystemd.git alloc-util: Move strdupa_safe() and strndupa_safe() to string-util.h --- diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h index 764a364a71b..f82530bdc24 100644 --- a/src/basic/alloc-util.h +++ b/src/basic/alloc-util.h @@ -223,19 +223,6 @@ static inline size_t malloc_sizeof_safe(void **xp) { MALLOC_SIZEOF_SAFE(x)/sizeof((x)[0]), \ VOID_0)) -/* These are like strdupa()/strndupa(), but honour ALLOCA_MAX */ -#define strdupa_safe(s) \ - ({ \ - const char *_t = (s); \ - (char*) memdupa_suffix0(_t, strlen(_t)); \ - }) - -#define strndupa_safe(s, n) \ - ({ \ - const char *_t = (s); \ - (char*) memdupa_suffix0(_t, strnlen(_t, n)); \ - }) - /* Free every element of the array. */ static inline void free_many(void **p, size_t n) { assert(p || n == 0); diff --git a/src/basic/string-util.h b/src/basic/string-util.h index 3679af2d707..c555de41fe2 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -280,6 +280,19 @@ size_t strspn_from_end(const char *str, const char *accept); char* strdupspn(const char *a, const char *accept); char* strdupcspn(const char *a, const char *reject); +/* These are like strdupa()/strndupa(), but honour ALLOCA_MAX */ +#define strdupa_safe(s) \ + ({ \ + const char *_t = (s); \ + (char*) memdupa_suffix0(_t, strlen(_t)); \ + }) + +#define strndupa_safe(s, n) \ + ({ \ + const char *_t = (s); \ + (char*) memdupa_suffix0(_t, strnlen(_t, n)); \ + }) + char* find_line_startswith(const char *haystack, const char *needle); bool version_is_valid(const char *s);