Skip to content

Commit 79d59a1

Browse files
lib/string/: stpe*(): Use array notation with forward declarations
Signed-off-by: Alejandro Colomar <alx@kernel.org>
1 parent 2966551 commit 79d59a1

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

lib/string/sprintf/stpeprintf.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
1+
// SPDX-FileCopyrightText: 2022-2025, Alejandro Colomar <alx@kernel.org>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

@@ -10,8 +10,8 @@
1010

1111

1212
#if !defined(HAVE_STPEPRINTF)
13-
extern inline char *stpeprintf(char *dst, char *end, const char *restrict fmt,
14-
...);
15-
extern inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
16-
va_list ap);
13+
extern inline char *stpeprintf(char dst[], char end[];
14+
char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, ...);
15+
extern inline char *vstpeprintf(char dst[], char end[];
16+
char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, va_list ap);
1717
#endif

lib/string/sprintf/stpeprintf.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
1+
// SPDX-FileCopyrightText: 2022-2025, Alejandro Colomar <alx@kernel.org>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

@@ -17,10 +17,11 @@
1717

1818
#if !defined(HAVE_STPEPRINTF)
1919
format_attr(printf, 3, 4)
20-
inline char *stpeprintf(char *dst, char *end, const char *restrict fmt, ...);
20+
inline char *stpeprintf(char dst[], char end[];
21+
char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, ...);
2122
format_attr(printf, 3, 0)
22-
inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
23-
va_list ap);
23+
inline char *vstpeprintf(char dst[], char end[];
24+
char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, va_list ap);
2425
#endif
2526

2627

@@ -76,7 +77,8 @@ inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
7677

7778
#if !defined(HAVE_STPEPRINTF)
7879
inline char *
79-
stpeprintf(char *dst, char *end, const char *restrict fmt, ...)
80+
stpeprintf(char dst[], char end[];
81+
char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, ...)
8082
{
8183
char *p;
8284
va_list ap;
@@ -92,7 +94,8 @@ stpeprintf(char *dst, char *end, const char *restrict fmt, ...)
9294

9395
#if !defined(HAVE_STPEPRINTF)
9496
inline char *
95-
vstpeprintf(char *dst, char *end, const char *restrict fmt, va_list ap)
97+
vstpeprintf(char dst[], char end[];
98+
char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, va_list ap)
9699
{
97100
int len;
98101
ptrdiff_t size;

lib/string/strcpy/stpecpy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88

99

1010
#if !defined(HAVE_STPECPY)
11-
extern inline char *stpecpy(char *dst, char *end, const char *restrict src);
11+
extern inline char *stpecpy(char dst[], char end[];
12+
char dst[dst ? end - dst : 0], char end[0], const char *restrict src);
1213
#endif

lib/string/strcpy/stpecpy.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
#if !defined(HAVE_STPECPY)
1919
ATTR_STRING(3)
20-
inline char *stpecpy(char *dst, char *end, const char *restrict src);
20+
inline char *stpecpy(char dst[], char end[];
21+
char dst[dst ? end - dst : 0], char end[0], const char *restrict src);
2122
#endif
2223

2324

@@ -65,7 +66,8 @@ inline char *stpecpy(char *dst, char *end, const char *restrict src);
6566

6667
#if !defined(HAVE_STPECPY)
6768
inline char *
68-
stpecpy(char *dst, char *end, const char *restrict src)
69+
stpecpy(char dst[], char end[];
70+
char dst[dst ? end - dst : 0], char end[0], const char *restrict src)
6971
{
7072
bool trunc;
7173
size_t dsize, dlen, slen;

0 commit comments

Comments
 (0)