2011-02-12 05:22:29 +00:00
|
|
|
#ifndef _STRING_H
|
|
|
|
#define _STRING_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-09-08 03:13:55 +00:00
|
|
|
#include <features.h>
|
2012-09-07 02:44:55 +00:00
|
|
|
|
use a common definition of NULL as 0L for C and C++
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.
2013-01-19 01:35:26 +00:00
|
|
|
#define NULL 0L
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
#define __NEED_size_t
|
2012-02-07 02:51:02 +00:00
|
|
|
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|
2012-05-23 01:52:08 +00:00
|
|
|
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|
|
|
|
|| defined(_BSD_SOURCE)
|
2012-02-07 02:51:02 +00:00
|
|
|
#define __NEED_locale_t
|
|
|
|
#endif
|
|
|
|
|
2011-02-12 05:22:29 +00:00
|
|
|
#include <bits/alltypes.h>
|
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
void *memcpy (void *__restrict, const void *__restrict, size_t);
|
2011-02-12 05:22:29 +00:00
|
|
|
void *memmove (void *, const void *, size_t);
|
|
|
|
void *memset (void *, int, size_t);
|
|
|
|
int memcmp (const void *, const void *, size_t);
|
|
|
|
void *memchr (const void *, int, size_t);
|
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
char *strcpy (char *__restrict, const char *__restrict);
|
|
|
|
char *strncpy (char *__restrict, const char *__restrict, size_t);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
char *strcat (char *__restrict, const char *__restrict);
|
|
|
|
char *strncat (char *__restrict, const char *__restrict, size_t);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
int strcmp (const char *, const char *);
|
|
|
|
int strncmp (const char *, const char *, size_t);
|
|
|
|
|
|
|
|
int strcoll (const char *, const char *);
|
2012-09-07 02:44:55 +00:00
|
|
|
size_t strxfrm (char *__restrict, const char *__restrict, size_t);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
char *strchr (const char *, int);
|
|
|
|
char *strrchr (const char *, int);
|
|
|
|
|
|
|
|
size_t strcspn (const char *, const char *);
|
|
|
|
size_t strspn (const char *, const char *);
|
|
|
|
char *strpbrk (const char *, const char *);
|
|
|
|
char *strstr (const char *, const char *);
|
2012-09-07 02:44:55 +00:00
|
|
|
char *strtok (char *__restrict, const char *__restrict);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
size_t strlen (const char *);
|
|
|
|
|
|
|
|
char *strerror (int);
|
|
|
|
|
2012-05-23 01:52:08 +00:00
|
|
|
#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2011-02-15 01:53:15 +00:00
|
|
|
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|
2012-05-23 01:52:08 +00:00
|
|
|
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|
|
|
|
|| defined(_BSD_SOURCE)
|
2012-09-07 02:44:55 +00:00
|
|
|
char *strtok_r (char *__restrict, const char *__restrict, char **__restrict);
|
2011-02-15 01:53:15 +00:00
|
|
|
int strerror_r (int, char *, size_t);
|
2012-09-07 02:44:55 +00:00
|
|
|
char *stpcpy(char *__restrict, const char *__restrict);
|
|
|
|
char *stpncpy(char *__restrict, const char *__restrict, size_t);
|
2011-02-12 05:22:29 +00:00
|
|
|
size_t strnlen (const char *, size_t);
|
2011-02-15 01:53:15 +00:00
|
|
|
char *strdup (const char *);
|
|
|
|
char *strndup (const char *, size_t);
|
2011-02-27 04:50:26 +00:00
|
|
|
char *strsignal(int);
|
2012-02-07 02:51:02 +00:00
|
|
|
char *strerror_l (int, locale_t);
|
|
|
|
int strcoll_l (const char *, const char *, locale_t);
|
2012-09-07 02:44:55 +00:00
|
|
|
size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
|
2011-02-15 01:53:15 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-23 01:52:08 +00:00
|
|
|
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|
|
|
|
|| defined(_BSD_SOURCE)
|
2012-09-07 02:44:55 +00:00
|
|
|
void *memccpy (void *__restrict, const void *__restrict, int, size_t);
|
2011-02-24 17:36:04 +00:00
|
|
|
#endif
|
|
|
|
|
2012-09-14 01:01:30 +00:00
|
|
|
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
|
|
|
char *strsep(char **, const char *);
|
2011-02-15 01:53:15 +00:00
|
|
|
size_t strlcat (char *, const char *, size_t);
|
|
|
|
size_t strlcpy (char *, const char *, size_t);
|
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
#ifdef _GNU_SOURCE
|
2012-05-23 01:52:08 +00:00
|
|
|
#define strdupa(x) strcpy(alloca(strlen(x)+1),x)
|
2011-09-12 02:45:56 +00:00
|
|
|
int strverscmp (const char *, const char *);
|
2012-05-23 01:52:08 +00:00
|
|
|
int strcasecmp_l (const char *, const char *, locale_t);
|
|
|
|
int strncasecmp_l (const char *, const char *, size_t, locale_t);
|
2011-02-12 05:22:29 +00:00
|
|
|
char *strchrnul(const char *, int);
|
2011-02-15 21:08:19 +00:00
|
|
|
char *strcasestr(const char *, const char *);
|
2012-10-16 03:02:57 +00:00
|
|
|
void *memmem(const void *, size_t, const void *, size_t);
|
2011-04-13 12:36:29 +00:00
|
|
|
void *memrchr(const void *, int, size_t);
|
2011-04-26 16:28:41 +00:00
|
|
|
void *mempcpy(void *, const void *, size_t);
|
2012-05-09 15:47:06 +00:00
|
|
|
#ifndef __cplusplus
|
2012-02-25 04:23:47 +00:00
|
|
|
char *basename();
|
2011-02-12 05:22:29 +00:00
|
|
|
#endif
|
2012-05-09 15:47:06 +00:00
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|