|
| 1 | +From 725e17ed6dff4d0cd22487bb64470881e86a92e7 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Rich Felker <dalias@aerifal.cx> |
| 3 | +Date: Mon, 6 Nov 2023 08:26:19 -0500 |
| 4 | +Subject: [PATCH] remove non-prototype declaration of basename from string.h |
| 5 | + |
| 6 | +commit 37bb3cce4598c19288628e675eaf1cda6e96958f suppressed the |
| 7 | +declaration for C++, where it is wrongly interpreted as declaring the |
| 8 | +function as taking no arguments. with C23 removing non-prototype |
| 9 | +declarations, that problem is now also relevant to C. |
| 10 | + |
| 11 | +the non-prototype declaration for basename originates with commit |
| 12 | +06aec8d7152dfb8360cb7ed9b3d7215ca0b0b500, where it was designed to |
| 13 | +avoid conflicts with programs which declare basename with the GNU |
| 14 | +signature taking const char *. that change was probably misguided, as |
| 15 | +it represents not only misaligned expectations with the caller, but |
| 16 | +also undefined behavior (calling a function that's been declared with |
| 17 | +the wrong type). |
| 18 | + |
| 19 | +we could opt to fix the declaration, but since glibc, with the |
| 20 | +gratuitously incompatible GNU-basename function, seems to be the only |
| 21 | +implementation that declares it in string.h, it seems better to just |
| 22 | +remove the declaration. this provides some warning if applications are |
| 23 | +being built expecting the GNU behavior but not getting it. if we |
| 24 | +declared it here, it would only produce a warning if the caller also |
| 25 | +declares it themselves (rare) or if the caller attempts to pass a |
| 26 | +const-qualified pointer. |
| 27 | +--- |
| 28 | + include/string.h | 3 --- |
| 29 | + 1 file changed, 3 deletions(-) |
| 30 | + |
| 31 | +diff --git a/include/string.h b/include/string.h |
| 32 | +index db73d2a92..83e2b9464 100644 |
| 33 | +--- a/include/string.h |
| 34 | ++++ b/include/string.h |
| 35 | +@@ -95,9 +95,6 @@ char *strchrnul(const char *, int); |
| 36 | + char *strcasestr(const char *, const char *); |
| 37 | + void *memrchr(const void *, int, size_t); |
| 38 | + void *mempcpy(void *, const void *, size_t); |
| 39 | +-#ifndef __cplusplus |
| 40 | +-char *basename(); |
| 41 | +-#endif |
| 42 | + #endif |
| 43 | + |
| 44 | + #ifdef __cplusplus |
0 commit comments