]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
alloc-util: Move strdupa_safe() and strndupa_safe() to string-util.h
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 5 May 2025 19:50:56 +0000 (21:50 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 6 May 2025 13:42:01 +0000 (15:42 +0200)
src/basic/alloc-util.h
src/basic/string-util.h

index 764a364a71bc5de3b0333aec5c710ef76d905db9..f82530bdc2419aea768e6220def8c73ea3fdd034 100644 (file)
@@ -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);
index 3679af2d707345c83acfa802d1c2482a0eaa39db..c555de41fe295b8679c0249e60d628a31fc1c17a 100644 (file)
@@ -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);