string/strcpy/strncpy.h \
string/strcpy/strtcpy.c \
string/strcpy/strtcpy.h \
+ string/strdup/memdup.c \
+ string/strdup/memdup.h \
string/strdup/strdup.c \
string/strdup/strdup.h \
string/strdup/strndupa.c \
Like strndup(3), but takes an array.
m/
- memdup()
+ memdup() // Unimplemented
Duplicate an object. Returns a pointer to the dup.
- MEMDUP()
+ memdup_T()
Like memdup(), but with type-safety checks.
strcpy/ - String copying
--- /dev/null
+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include "config.h"
+
+#include "string/strdup/memdup.h"
--- /dev/null
+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_STRDUP_MEMDUP_H_
+#define SHADOW_INCLUDE_LIB_STRING_STRDUP_MEMDUP_H_
+
+
+#include "config.h"
+
+#include <stddef.h>
+
+#include "alloc/malloc.h"
+
+
+// memdup_T - memory duplicate type-safe
+#define memdup_T(p, T) memdup_T_(p, typeas(T))
+#define memdup_T_(p, T) \
+({ \
+ T *new_; \
+ \
+ new_ = malloc_T(1, T); \
+ if (new_ != NULL) \
+ *new_ = *(p); \
+ new_; \
+})
+
+
+#endif // include guard