Commit Graph

62 Commits

Author SHA1 Message Date
Corinna Vinschen ad101bcb0f Rename <xlocale.h> back to <sys/_locale.h>
libX11 provides <X11/Xlocale.h>.  The build of libX11 itself adds
include/X11 to the compiler's include path.  This results in a name
collision with /usr/include/xlocale.h on case-insensitive filesystems.

Commit 90e35b1eb3 renamed sys/_locale.h to xlocale.h in March 2017 under
the assumption that we should provide the locale_t type in the same file
as on Linux, FreeBSD, and Darwin.

A few weeks later (June 2017), glibc removed the xlocale.h file in favor
of bits/types/locale_t.h, which shouldn't be included directly anyway.

For reference and the reasoning, see
https://sourceware.org/git/?p=glibc.git;a=commit;h=f0be25b6336d

Given the above, revert 90e35b1eb3 and
fix additional usage of xlocale.h.
2019-06-14 10:02:08 +02:00
Sebastian Huber 201bbec6e4 Add attributes to malloc-like functions
These attributes help static analysis tools to produce less false
positives, e.g. double free warnings.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-10-10 07:40:06 +02:00
Yaakov Selkowitz 70ee6b17df ansification: remove _EXFUN, _EXFUN_NOTHROW
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17 11:47:29 -06:00
Yaakov Selkowitz e6321aa6a6 ansification: remove _PTR
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17 11:47:16 -06:00
Yaakov Selkowitz e4fc4d7bc4 ssp: add Object Size Checking for string.h
The implementation is from NetBSD, with the addition of mempcpy (a GNU
extension) for parity with glibc and libssp.

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-11-29 11:25:40 -06:00
Yaakov Selkowitz 36a0a675b4 Make __nonnull macro compatible with glibc
This form allows for multiple arguments, e.g. __nonnull((1,2)).

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-11-28 10:26:29 -06:00
Sichen Zhao c206d04422 Port strnstr.c to newlib. 2017-08-25 18:00:46 +02:00
David Macek bf61b38d98 Rename __in and __out in headers to avoid collision with Windows APIs
* string.h: Local variables in expansion of strdupa and strndupa
* sys/wait.h: Fields in anonymous union in expansion of __wait_status_to_int
2017-07-07 16:37:44 +02:00
Sebastian Huber 2390e71a42 Synchronize <strings.h> with latest FreeBSD
Include <strings.h> in <string.h> if __BSD_VISIBLE like on FreeBSD.
Remove redundant declarations from <string.h>.  Make ffsl(), ffsll(),
strncasecmp(), strcasecmp_l(), and strncasecmp_l() visible via
__BSD_VISIBLE instead of __GNU_VISIBLE.  Add fls(), flsl(), and flsll()
to <strings.h> if __BSD_VISIBLE.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-07-05 13:49:48 +02:00
Yaakov Selkowitz 59e09b6419 string: add strverscmp
The actual implementation is from musl (MIT license).

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-06-19 08:16:42 -05:00
Yaakov Selkowitz 90e35b1eb3 Rename <sys/_locale.h> to <xlocale.h>
The locale_t type is provided by <xlocale.h> on Linux, FreeBSD, and Darwin.
While, like on some of those systems, it is automatically included by
<locale.h> with the proper feature test macros, its presence under this
particular name is still presumed in real-world software.

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-03-22 10:03:45 +01:00
Brian Inglis 448b46397d Add strerror_l prototype, change str[n]casecmp_l feature tests
strerror_l prototype was missing.
str[n]casecmp_l feature tests in string.h vs. strings.h were transposed.
2016-08-25 09:44:31 +02:00
Corinna Vinschen 7156bf842e Add sys/_locale.h header and fix up headers
Signed-off by: Corinna Vinschen <corinna@vinschen.de>
2016-08-15 10:56:58 +02:00
Corinna Vinschen c1b7d9d93d Implement per-locale string functions
strcasecmp_l, strcoll_l, strncasecmp_l, strxfrm_l,
wcscasecmp_l, wcscoll_l, wcstrncasecmp_l, wcstrxfrm_l,
strftime_l.

Add missing CHEWOUT_FILES from previous patch.

TODO: strfmon_l.

Signed-off by: Corinna Vinschen <corinna@vinschen.de>
2016-08-15 10:56:58 +02:00
Yaakov Selkowitz 9f90ae0435 Feature test macros overhaul: string.h and strings.h overlaps
strings.h is the header mandated for these functions in POSIX.1 prior to
2008 (when most of these were removed).  The declarations in string.h are
only for BSD compatibility.  But when both headers are included, avoid
duplicate declarations.

Also, mark stpcpy and stpncpy as POSIX.1-2008.

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2016-04-13 23:50:11 -05:00
Sebastian Huber 55c239d834 Add timingsafe_memcmp()
This function is used by LibreSSL and OpenSSH and is provided by the
OpenBSD libc.

	* libc/include/string.h (timingsafe_memcmp): Declare.
	* libc/string/timingsafe_memcmp.c: New file.
	* libc/string/Makefile.am: Add new file.
	* libc/string/Makefile.in: Regenerate.
2016-03-18 12:33:40 +01:00
Sebastian Huber 559fd77dda Add timingsafe_bcmp()
This function is used by LibreSSL and OpenSSH and is provided by the
OpenBSD libc.

	* libc/include/string.h (timingsafe_bcmp): Declare.
	* libc/string/timingsafe_bcmp.c: New file.
	* libc/string/Makefile.am: Add new file.
	* libc/string/Makefile.in: Regenerate.
2016-03-18 12:33:40 +01:00
Sebastian Huber 8740fa7fd0 Add explicit_bzero()
This function is used by LibreSSL and OpenSSH and is provided by the
OpenBSD libc.

	* libc/include/string.h (explicit_bzero): Declare.
	* libc/string/explicit_bzero.c: New file.
	* libc/string/Makefile.am: Add new file.
	* libc/string/Makefile.in: Regenerate.
2016-03-18 12:33:40 +01:00
Yaakov Selkowitz 615d63599b Feature test macros overhaul: string.h
Throughout, remove __STRICT_ANSI__ and use the proper internal macros.

bcmp, bcopy, bzero, index, and rindex were in POSIX prior to 2008.

memrchr is GNU.

strdup and strndup are POSIX.1-2008.

The int-returning form of strerror_r is POSIX.1-2001.

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2016-03-17 21:09:07 -05:00
Yaakov Selkowitz 79e419de62 Rework handling of basename variants
As a commonly-included header, the #define basename in <string.h> can
affect code which uses "basename" for its own purposes (e.g. struct
members or C++ namespaced functions).  When such cases occur and some
code includes <string.h> and some not, then errors result.  OTOH,
<libgen.h> is rarely used, and that's where the renaming occurs in
glibc, so code using <libgen.h> should already be safe.

* libc/include/libgen.h (basename): Define as __xpg_basename
for source compatibility with glibc.
Declare with __ASMNAME("basename") for ABI compatibility.
* libc/include/string.h (basename): Define as basename for
source compatibility with glibc.
Declare with __ASMNAME("__gnu_basename") for ABI compatibility.
2015-07-06 14:58:51 -05:00
Corinna Vinschen 97a5dda2b0 Fix basename prototype collision string.h vs libgen.h
* libc/include/libgen.h (basename): Drop defining _BASENAME_DEFINED.
        Always define macro basename.  Add comment to explain why.
        * libc/include/string.h (basename): Check for basename instead of
        _BASENAME_DEFINED.  Drop __GNUC__ branch, always use basename macro.
        Change comment to explain why.  Add nonnull function attribute.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-04-23 22:03:45 +02:00
Yaakov Selkowitz d67052321e string: add GNU basename(3)
* libc/include/libgen.h (_BASENAME_DEFINED): Define.
* libc/include/string.h (basename): Declare.
* libc/string/Makefile.am (ELIX_4_SOURCES): Add gnu_basename.c.
* libc/string/Makefile.in: Regenerate.
* libc/string/gnu_basename.c: New file.
2015-04-23 21:57:07 +02:00
Nick Clifton b9e7cd9a84 * libc/include/complex.h (cabsl): Add prototype.
(cimagl): Add prototype.
	(creall): Add prototype.
	* libc/include/ieeefp.h: Include float.h.
	(EXT_EXPBITS, EXT_FRACHBITS, EXT_FRACLBITS)
	(EXT_EXP_INFNAN. EXT_EXP_BIAS, EXT_FRACBITS): Define.
	(struct ieee_ext, union ieee_ext_u): New types for long double
	support.
	* libc/include/math.h (finitel): Add prototype.
	(hypotl): Add prototype.
	(sqrtl): Add prototype.
	* libm/common/Makefile.am (lsrc): Add sl_finite.c.
	* libm/common/Makefile.in: Regenerate.
	* libm/common/fdlibm.h (__ieee754_hypotl): Add prototype.
	* libm/common/hypotl.c (hypotl): Add implementation for when long
	double is larger than double.
	* libm/common/sqrtl.c (sqrtl): Likewise.
	* libm/common/sl_finite.c: New file.  Adds implementation of the
	finitel function.
	* libm/complex/Makefile.am (lsrc): Define.
	(libcomplex_la_SOURCES): Add lsrc.
	(lib_a_SOURCES): Add lsrc.
	* libm/complex/Makefile.in: Regenerate.
	* libm/complex/cabs.c: Add documentation of cabsl function.
	* libm/complex/cimag.c: Add documentation of cimagl function.
	* libm/complex/creall.c: Add documentation of creall function.
	* libm/complex/cabsl.c: New file.  Adds implementation of the
	cabsl function.
	* libm/complex/cimagl.c: New file.  Adds implementation of the
	cimagl function.
	* libm/complex/creall.c: New file.  Adds implementation of the
	creall function.
	* libm/math/Makefile.am (lsrc): Define.
	(libmath_la_SOURCES): Add lsrc.
	(lib_a_SOURCES): Add lsrc.
	* libm/math/Makefile.in: Regenerate.
	* libm/math/el_hypot.c: New file.  Adds implementation of the
	__ieee754_hypotl function.
2015-02-06 16:14:04 +00:00
Jon TURNEY e7ebfb119e 2014-10-29 Jon Turney <jon.turney@dronecode.org.uk>
* libc/include/string.h: Correct guard for strcasecmp().
2014-10-30 11:25:17 +00:00
Corinna Vinschen da77c6d1e5 * libc/include/string.h (ffsl): Declare as GNU function.
(ffsll): Ditto.
2014-10-08 21:04:59 +00:00
Jeff Johnston ad9ed96b6b 2014-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
Thomas Uhle <thomas.uhle@eas.iis.fraunhofer.de>

        * libc/include/string.h: Correct guard for strnlen().
2014-09-16 19:59:01 +00:00
Joel Sherrill 81c17949f0 2014-08-18 Joel Sherrill <joel.sherrill@oarcorp.com>
* libc/include/string.h: Improve language and OS standard guards.
2014-08-18 14:18:10 +00:00
Corinna Vinschen b143d094ee * libc/sys/linux/include/netdb.h, libc/sys/linux/net/getaddrinfo.c,
libc/sys/linux/net/getnameinfo.c: Add restrict keyword to getnameinfo()
	and getaddrinfo() to increase standards compliance and match glibc.

	* libc/include/string.h, libc/string/memccpy.c, libc/string/memcpy.c,
	libc/string/stpcpy.c, libc/string/stpncpy.c, libc/string/strcat.c,
	libc/string/strncat.c, libc/string/strncpy.c, libc/string/strtok.c,
	libc/string/strtok_r.c, libc/string/strxfrm.c
	libc/machine/microblaze/strcpy.c, libc/machine/xscale/memcpy.c,
	libc/machine/cris/memcpy.c: Add __restrict to prototype to
	increase standards compliance.
2013-07-23 07:05:31 +00:00
Yaakov Selkowitz e3928ce48c * libc/include/string.h (rawmemchr): Declare.
* libc/string/Makefile.am (ELIX_4_SOURCES): Add rawmemchr.c.
(CHEWOUT_FILES): Add rawmemchr.def.
* libc/string/Makefile.in: Regenerate.
* libc/string/rawmemchr.c: New file.
2013-06-24 15:11:24 +00:00
Corinna Vinschen 38305196bf * libc/include/string.h: Fix preprocessor expressions using
_XOPEN_SOURCE.
2013-01-12 10:55:09 +00:00
Corinna Vinschen de1e3bb2c9 * libc/include/locale.h (NULL): Fetch definition via stddef.h.
* libc/include/stdio.h (NULL): Ditto.
	* libc/include/stdlib.h (NULL): Ditto.
	* libc/include/string.h (NULL): Ditto.
	* libc/include/wchar.h (NULL): Ditto.
	* libc/include/rpc/types.h (NULL): Ditto.
	* libc/include/time.h (NULL): Ditto.  Include stddef.h earlier.
2012-11-01 11:51:12 +00:00
Corinna Vinschen 6f7ae529ad * libc/include/string.h (strdup, strndup): Declare if not
__STRICT_ANSI__ or _XOPEN_SOURCE is defined appropriately.
2012-10-22 15:16:48 +00:00
Corinna Vinschen 507b172d8d * libc/include/string.h (memrchr): Declare.
* libc/string/Makefile.am (ELIX_4_SOURCES): Add memrchr.c.
	(CHEWOUT_FILES): Add memrchr.def.
	* libc/string/Makefile.in: Regenerate.
	* libc/string/memrchr.c: New file.
2012-05-10 08:34:08 +00:00
Jeff Johnston 38e356f0e4 2011-06-09 Yaakov Selkowitz <yselkowitz@...>
* libc/include/string.h (strdupa): New macro function.
        (strndupa): New macro function.
2011-06-10 18:30:38 +00:00
Eric Blake 4805b60ccf strerror: allow user hook to comply with POSIX rules
* libc/string/strerror.c (strerror): Split body into...
(_strerror_r): ...new reentrant function.
* libc/string/u_strerr.c (_user_strerror): Update signature.
* libc/include/stdio.h (_strerror_r): New prototype.
* libc/posix/collate.c (__collate_err): Adjust callers.
* libc/stdio/perror.c (_perror_r): Likewise.
* libc/string/strerror_r.c (strerror_r): Likewise.
* libc/string/xpg_strerror_r.c (__xpg_strerror_r): Likewise.
2011-05-25 18:41:10 +00:00
Corinna Vinschen 43ff4129ce * libc/include/string.h (strchrnul): Declare.
* libc/string/strchrnul.c: New file.
	* libc/string/Makefile.am (ELIX_2_SOURCES): Add strchrnul.c.
	* libc/string/Makefile.in: Regenerate.
2011-03-28 14:51:28 +00:00
Corinna Vinschen 4b43b20be8 * libc/include/string.h: Include sys/cdefs.h. 2011-03-03 11:11:41 +00:00
Corinna Vinschen 977cd4175e * libc/include/sys/cdefs.h (__CONCAT1): Define.
(__CONCAT): Define.
	(__STRING): Define.
	(__XSTRING): Define.
	(__ASMNAME): Define.
	* libc/include/string.h (strerror_r): Use __ASMNAME to take target
	specific label prefixes into account.
2011-03-03 10:37:09 +00:00
Eric Blake 7c10a76dec strerror_r: provide POSIX implementation
* libc/include/string.h (strerror_r): Update declaration.
* libc/string/strerror.c (strerror): Update documentation.
* libc/string/strerror_r.c (strerror_r): Always return
NUL-terminated string; don't overwrite too-short buf.
* libc/string/xpg_strerror_r.c (__xpg_strerror_r): Implement POSIX
variant.
* libc/string/Makefile.am (GENERAL_SOURCES): Build new file.
* libc/string/Makefile.in: Regenerate.
2011-02-10 16:48:18 +00:00
Corinna Vinschen 84ca64afa6 * libc/include/string.h: Make strsignal() available unconditionally. 2011-01-10 10:59:42 +00:00
Eric Blake 8fa475e4b1 Per Posix, strsignal returns non-const char*.
* libc/include/string.h (strsignal): Fix return type.
2008-06-18 15:27:41 +00:00
Eric Blake 40617efc8b Make strstr and strcasestr O(n), not O(n^2); add memmem.
* libc/string/str-two-way.h: New file.
* libc/string/memmem.c (memmem): New file.
* libc/include/string.h (memmem): Declare for all platforms.
* libc/string/strstr.c (strstr): Provide O(n) implementation when
not optimizing for space.
* libc/string/strcasestr.c (strcasestr): Likewise.
* libc/string/Makefile.am (ELIX_SOURCES): Rename to...
(ELIX_2_SOURCES): ...this.
(ELIX_4_SOURCES): New category, for memmem.
(lib_a_SOURCES, libstring_la_SOURCES): Build new file.
(CHEWOUT_FILES): Build documentation for memmem.
* libc/string/strings.tex: Include new docs.
2008-01-12 04:25:55 +00:00
Corinna Vinschen 5d8b97a694 * libc/include/string.h: Add prototypes for stpcpy and stpncpy.
* libc/string/Makefile.am (ELIX_SOURCES): Add stpcpy.c and
	stpncpy.c.
	(CHEWOUT_FILES): Add stpcpy.def and stpncpy.def.
	* libc/string/Makefile.in: Regenerate.
	* libc/string/stpcpy.c: New file.
	* libc/string/stpncpy.c: New file.
	* libc/string/strings.tex: Add stpcpy and stpncpy.
2007-06-28 17:07:23 +00:00
Jeff Johnston 6fb374754d 2007-06-08 Jeff Johnston <jjohnstn@redhat.com>
* libc/string/strcasestr.c: New file.
        * libc/include/string.h: Add strcasestr.
        * libc/string/strings.tex: Add strcasestr.
        * libc/string/Makefile.am: Ditto.
        * libc/string/Makefile.in: Regenerated.
2007-06-08 18:38:51 +00:00
Christopher Faylor 86c6c4212f * libc/include/string.h: Add cygwin-specific function declaration. 2005-11-08 22:10:33 +00:00
Christopher Faylor dbeee890d4 * libc/include/string.h: Revert previous change. 2005-08-26 04:33:02 +00:00
Christopher Faylor 377d3ea0e2 * libc/include/string.h: For Cygwin, Define strerror_r as per ISO C. 2005-08-25 23:02:24 +00:00
Jeff Johnston dbfa92dd94 2005-01-24 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/string.h: Remove Linux-specific declaration of
        strsignal and add #include <sys/string.h>.
        * libc/include/sys/string.h: New file.
        * libc/include/sys/linux/sys/string.h: New file with strsignal
        declaration deleted above.
2005-01-24 18:46:09 +00:00
Jeff Johnston d254189b38 2002-07-23 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/string.h: Add mempcpy, strndup, and _strndup_r
        prototypes.
        * libc/stdlib/Makefile.am: Remove strdup.c and strdup_r.c.
        * libc/stdlib/Makefile.in: Regenerated.
        * libc/stdlib/strdup.c: Removed.
        * libc/stdlib/strdup_r.c: Removed.
        * libc/string/Makefile.am: Add strdup.c, strdup_r.c, memccpy.c,
        mempcpy.c, strndup.c, and strndup_r.c.
        * libc/string/Makefile.in: Regenerated.
        * libc/string/memccpy.c: New file.
        * libc/string/mempcpy.c: Ditto.
        * libc/string/strndup.c: Ditto.
        * libc/string/strndup_r.c: Ditto.
        * libc/string/strdup.c: New file moved from stdlib.
        * libc/string/strdup_r.c: Ditto.
        * libc/string/strings.tex: Add memccpy and mempcpy documentation.
2002-07-23 21:38:00 +00:00
Jeff Johnston c1a3171f2d 2002-06-27 Benjamin Kosnik <bkoz@redhat.com>
* libc/include/stdio.h: Untangle, add _BEGIN_STD_C and _END_STD_C.
        * libc/include/time.h: Same.
        * libc/include/string.h: Same.
        * libc/include/stdlib.h: Same.
        * libc/include/signal.h: Same.
        * libc/include/setjmp.h: Same.
        * libc/include/math.h: Same.
        * libc/include/locale.h: Same.
        * libc/include/ctype.h: Same.
        * libc/include/machine/setjmp.h: Same.
        * libc/include/_ansi.h (_BEGIN_STD_C): Add.
        (_END_STD_C): Add.
2002-06-27 23:58:38 +00:00