Skip to content

Commit ec706b4

Browse files
lib/string/strdup/: XSTRNDUP(): Reimplement in terms of X()
This is much simpler. Signed-off-by: Alejandro Colomar <[email protected]>
1 parent b4f10a2 commit ec706b4

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lib/string/strdup/xstrndup.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]>
1+
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

@@ -10,16 +10,12 @@
1010

1111
#include <string.h>
1212

13-
#include "alloc/x/xmalloc.h"
1413
#include "sizeof.h"
15-
#include "string/strcpy/strncat.h"
14+
#include "x.h"
1615

1716

1817
// Similar to strndup(3), but ensure that 's' is an array, and exit on ENOMEM.
19-
#define XSTRNDUP(s) \
20-
( \
21-
STRNCAT(strcpy(XMALLOC(strnlen(s, countof(s)) + 1, char), ""), s) \
22-
)
18+
#define XSTRNDUP(s) X(strndup(s, countof(s)))
2319

2420

2521
#endif // include guard

0 commit comments

Comments
 (0)