Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d509cc

Browse files
lib/string/strdup/strndupa.h: STRNDUPA(): Simplify implementation
Signed-off-by: Alejandro Colomar <[email protected]>
1 parent 2353707 commit 5d509cc

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

lib/string/strdup/strndupa.h

Lines changed: 2 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

@@ -12,19 +12,14 @@
1212
#include <string.h>
1313

1414
#include "sizeof.h"
15-
#include "string/strcpy/strncat.h"
1615

1716

1817
#ifndef strndupa
1918
# define strndupa(s, n) strncat(strcpy(alloca(n + 1), ""), s, n)
2019
#endif
2120

2221

23-
// Similar to strndupa(3), but ensure that 's' is an array.
24-
#define STRNDUPA(s) \
25-
( \
26-
STRNCAT(strcpy(alloca(strnlen(s, NITEMS(s)) + 1), ""), s) \
27-
)
22+
#define STRNDUPA(s) strndupa(s, NITEMS(s))
2823

2924

3025
#endif // include guard

0 commit comments

Comments
 (0)