musl/include/string.h, branch master musl - an implementation of the standard library for Linux-based systems remove non-prototype declaration of basename from string.h 2023年11月06日T13:26:19+00:00 Rich Felker dalias@aerifal.cx 2023年11月06日T13:26:19+00:00 725e17ed6dff4d0cd22487bb64470881e86a92e7 commit 37bb3cce4598c19288628e675eaf1cda6e96958f suppressed the declaration for C++, where it is wrongly interpreted as declaring the function as taking no arguments. with C23 removing non-prototype declarations, that problem is now also relevant to C. the non-prototype declaration for basename originates with commit 06aec8d7152dfb8360cb7ed9b3d7215ca0b0b500, where it was designed to avoid conflicts with programs which declare basename with the GNU signature taking const char *. that change was probably misguided, as it represents not only misaligned expectations with the caller, but also undefined behavior (calling a function that's been declared with the wrong type). we could opt to fix the declaration, but since glibc, with the gratuitously incompatible GNU-basename function, seems to be the only implementation that declares it in string.h, it seems better to just remove the declaration. this provides some warning if applications are being built expecting the GNU behavior but not getting it. if we declared it here, it would only produce a warning if the caller also declares it themselves (rare) or if the caller attempts to pass a const-qualified pointer.
commit 37bb3cce4598c19288628e675eaf1cda6e96958f suppressed the
declaration for C++, where it is wrongly interpreted as declaring the
function as taking no arguments. with C23 removing non-prototype
declarations, that problem is now also relevant to C.
the non-prototype declaration for basename originates with commit
06aec8d7152dfb8360cb7ed9b3d7215ca0b0b500, where it was designed to
avoid conflicts with programs which declare basename with the GNU
signature taking const char *. that change was probably misguided, as
it represents not only misaligned expectations with the caller, but
also undefined behavior (calling a function that's been declared with
the wrong type).
we could opt to fix the declaration, but since glibc, with the
gratuitously incompatible GNU-basename function, seems to be the only
implementation that declares it in string.h, it seems better to just
remove the declaration. this provides some warning if applications are
being built expecting the GNU behavior but not getting it. if we
declared it here, it would only produce a warning if the caller also
declares it themselves (rare) or if the caller attempts to pass a
const-qualified pointer.
expose memmem under baseline POSIX feature profile 2023年01月06日T11:33:19+00:00 Rich Felker dalias@aerifal.cx 2023年01月06日T11:33:19+00:00 a4b0a665b84c4a3117cca152fe28c204d23ece46 memmem has been adopted for the next issue of POSIX (outcome of tracker item 1061). since mem* is in the reserved namespace for string.h it's already fully conforming to expose it by default, so just do so.
memmem has been adopted for the next issue of POSIX (outcome of
tracker item 1061). since mem* is in the reserved namespace for
string.h it's already fully conforming to expose it by default, so
just do so.
define NULL as nullptr when used in C++11 or later 2021年11月29日T22:45:21+00:00 Ismael Luceno ismael@iodev.co.uk 2021年08月15日T15:51:57+00:00 98e688a9da5e7b2925dda17a2d6820dddf1fb287 This should be safer for casting and more compatible with existing code bases that wrongly assume it must be defined as a pointer.
This should be safer for casting and more compatible with existing code
bases that wrongly assume it must be defined as a pointer.
add explicit_bzero implementation 2018年06月26日T20:59:12+00:00 David Carlier dcarlier@afilias.info 2018年06月15日T13:30:09+00:00 05ac345f895098657cf44d419b5d572161ebaf43 maintainer's note: past sentiment was that, despite being imperfect and unable to force clearing of all possible copies of sensitive data (e.g. in registers, register spills, signal contexts left on the stack, etc.) this function would be added if major implementations agreed on it, which has happened -- several BSDs and glibc all include it.
maintainer's note: past sentiment was that, despite being imperfect
and unable to force clearing of all possible copies of sensitive data
(e.g. in registers, register spills, signal contexts left on the
stack, etc.) this function would be added if major implementations
agreed on it, which has happened -- several BSDs and glibc all include
it.
remove useless declarations in string.h 2017年07月04日T21:04:21+00:00 Alexander Monakov amonakov@ispras.ru 2017年07月03日T16:24:02+00:00 bd00cc87819875882356298b6c6bdabc1700753f The two functions str{,n}casecmp_l are specified to be declared in <strings.h> which is already included from <string.h> under _GNU_SOURCE.
The two functions str{,n}casecmp_l are specified to be declared in
<strings.h> which is already included from <string.h> under _GNU_SOURCE.
restore type of NULL to void * except when used in C++ programs 2013年11月25日T02:42:55+00:00 Rich Felker dalias@aerifal.cx 2013年11月25日T02:42:55+00:00 c8a9c22173f485c8c053709e1dfa0a617cb6be1a unfortunately this eliminates the ability of the compiler to diagnose some dangerous/incorrect usage, but POSIX requires (as an extension to the C language, i.e. CX shaded) that NULL have type void *. plain C allows it to be defined as any null pointer constant. the definition 0L is preserved for C++ rather than reverting to plain 0 to avoid dangerous behavior in non-conforming programs which use NULL as a variadic sentinel. (it's impossible to use (void *)0 for C++ since C++ lacks the proper implicit pointer conversions, and other popular alternatives like the GCC __null extension seem non-conforming to the standard's requirements.)
unfortunately this eliminates the ability of the compiler to diagnose
some dangerous/incorrect usage, but POSIX requires (as an extension to
the C language, i.e. CX shaded) that NULL have type void *. plain C
allows it to be defined as any null pointer constant.
the definition 0L is preserved for C++ rather than reverting to plain
0 to avoid dangerous behavior in non-conforming programs which use
NULL as a variadic sentinel. (it's impossible to use (void *)0 for C++
since C++ lacks the proper implicit pointer conversions, and other
popular alternatives like the GCC __null extension seem non-conforming
to the standard's requirements.)
use a common definition of NULL as 0L for C and C++ 2013年01月19日T01:35:26+00:00 Rich Felker dalias@aerifal.cx 2013年01月19日T01:35:26+00:00 41d7c77d6a2e74294807d35062e4cd1d48ab72d3 the historical mess of having different definitions for C and C++ comes from the historical C definition as (void *)0 and the fact that (void *)0 can't be used in C++ because it does not convert to other pointer types implicitly. however, using plain 0 in C++ exposed bugs in C++ programs that call variadic functions with NULL as an argument and (wrongly; this is UB) expect it to arrive as a null pointer. on 64-bit machines, the high bits end up containing junk. glibc dodges the issue by using a GCC extension __null to define NULL; this is observably non-conforming because a conforming application could observe the definition of NULL via stringizing and see that it is neither an integer constant expression with value zero nor such an expression cast to void. switching to 0L eliminates the issue and provides compatibility with broken applications, since on all musl targets, long and pointers have the same size, representation, and argument-passing convention. we could maintain separate C and C++ definitions of NULL (i.e. just use 0L on C++ and use (void *)0 on C) but after careful analysis, it seems extremely difficult for a C program to even determine whether NULL has integer or pointer type, much less depend in subtle, unintentional ways, on whether it does. C89 seems to have no way to make the distinction. on C99, the fact that (int)(void *)0 is not an integer constant expression, along with subtle VLA/sizeof semantics, can be used to make the distinction, but many compilers are non-conforming and give the wrong result to this test anyway. on C11, _Generic can trivially make the distinction, but it seems unlikely that code targetting C11 would be so backwards in caring which definition of NULL an implementation uses. as such, the simplest path of using the same definition for NULL in both C and C++ was chosen. the #undef directive was also removed so that the compiler can catch and give a warning or error on redefinition if buggy programs have defined their own versions of NULL prior to inclusion of standard headers.
the historical mess of having different definitions for C and C++
comes from the historical C definition as (void *)0 and the fact that
(void *)0 can't be used in C++ because it does not convert to other
pointer types implicitly. however, using plain 0 in C++ exposed bugs
in C++ programs that call variadic functions with NULL as an argument
and (wrongly; this is UB) expect it to arrive as a null pointer. on
64-bit machines, the high bits end up containing junk. glibc dodges
the issue by using a GCC extension __null to define NULL; this is
observably non-conforming because a conforming application could
observe the definition of NULL via stringizing and see that it is
neither an integer constant expression with value zero nor such an
expression cast to void.
switching to 0L eliminates the issue and provides compatibility with
broken applications, since on all musl targets, long and pointers have
the same size, representation, and argument-passing convention. we
could maintain separate C and C++ definitions of NULL (i.e. just use
0L on C++ and use (void *)0 on C) but after careful analysis, it seems
extremely difficult for a C program to even determine whether NULL has
integer or pointer type, much less depend in subtle, unintentional
ways, on whether it does. C89 seems to have no way to make the
distinction. on C99, the fact that (int)(void *)0 is not an integer
constant expression, along with subtle VLA/sizeof semantics, can be
used to make the distinction, but many compilers are non-conforming
and give the wrong result to this test anyway. on C11, _Generic can
trivially make the distinction, but it seems unlikely that code
targetting C11 would be so backwards in caring which definition of
NULL an implementation uses.
as such, the simplest path of using the same definition for NULL in
both C and C++ was chosen. the #undef directive was also removed so
that the compiler can catch and give a warning or error on
redefinition if buggy programs have defined their own versions of
NULL prior to inclusion of standard headers.
feature test macros: make _GNU_SOURCE enable everything 2012年12月03日T21:57:01+00:00 Rich Felker dalias@aerifal.cx 2012年12月03日T21:57:01+00:00 769fd4ce202225ba1f2621bbefb803ee9a268ebf previously, a few BSD features were enabled only by _BSD_SOURCE, not by _GNU_SOURCE. since _BSD_SOURCE is default in the absence of other feature test macros, this made adding _GNU_SOURCE to a project not a purely additive feature test macro; it actually caused some features to be suppressed. most of the changes made by this patch actually bring musl in closer alignment with the glibc behavior for _GNU_SOURCE. the only exceptions are the added visibility of functions like strlcpy which were BSD-only due to being disliked/rejected by glibc maintainers. here, I feel the consistency of having _GNU_SOURCE mean "everything", and especially the property of it being purely additive, are more valuable than hiding functions which glibc does not have.
previously, a few BSD features were enabled only by _BSD_SOURCE, not
by _GNU_SOURCE. since _BSD_SOURCE is default in the absence of other
feature test macros, this made adding _GNU_SOURCE to a project not a
purely additive feature test macro; it actually caused some features
to be suppressed.
most of the changes made by this patch actually bring musl in closer
alignment with the glibc behavior for _GNU_SOURCE. the only exceptions
are the added visibility of functions like strlcpy which were BSD-only
due to being disliked/rejected by glibc maintainers. here, I feel the
consistency of having _GNU_SOURCE mean "everything", and especially
the property of it being purely additive, are more valuable than
hiding functions which glibc does not have.
add memmem function (gnu extension) 2012年10月16日T03:02:57+00:00 Rich Felker dalias@aerifal.cx 2012年10月16日T03:02:57+00:00 c86f2974e2acd330be2d587173dd4dd56db82e22 based on strstr. passes gnulib tests and a few quick checks of my own.
based on strstr. passes gnulib tests and a few quick checks of my own.
strsep is BSD|GNU, not GNU-only; it's originally from BSD 2012年09月14日T01:01:30+00:00 Rich Felker dalias@aerifal.cx 2012年09月14日T01:01:30+00:00 e2f6a3257e256ac26a755fb58290ceb1b839fa20

AltStyle によって変換されたページ (->オリジナル) /