modernc.org/cc@v1.0.1/v2/headers/linux_386/usr/include/string.h (about)

     1  /* Copyright (C) 1991-2018 Free Software Foundation, Inc.
     2     This file is part of the GNU C Library.
     3  
     4     The GNU C Library is free software; you can redistribute it and/or
     5     modify it under the terms of the GNU Lesser General Public
     6     License as published by the Free Software Foundation; either
     7     version 2.1 of the License, or (at your option) any later version.
     8  
     9     The GNU C Library is distributed in the hope that it will be useful,
    10     but WITHOUT ANY WARRANTY; without even the implied warranty of
    11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    12     Lesser General Public License for more details.
    13  
    14     You should have received a copy of the GNU Lesser General Public
    15     License along with the GNU C Library; if not, see
    16     <http://www.gnu.org/licenses/>.  */
    17  
    18  /*
    19   *	ISO C99 Standard: 7.21 String handling	<string.h>
    20   */
    21  
    22  #ifndef	_STRING_H
    23  #define	_STRING_H	1
    24  
    25  #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
    26  #include <bits/libc-header-start.h>
    27  
    28  __BEGIN_DECLS
    29  /* Get size_t and NULL from <stddef.h>.  */
    30  #define	__need_size_t
    31  #define	__need_NULL
    32  #include <stddef.h>
    33  /* Tell the caller that we provide correct C++ prototypes.  */
    34  #if defined __cplusplus && __GNUC_PREREQ (4, 4)
    35  # define __CORRECT_ISO_CPP_STRING_H_PROTO
    36  #endif
    37  /* Copy N bytes of SRC to DEST.  */
    38  extern void *memcpy(void *__restrict __dest, const void *__restrict __src, size_t __n)
    39  __THROW __nonnull((1, 2));
    40  /* Copy N bytes of SRC to DEST, guaranteeing
    41     correct behavior for overlapping strings.  */
    42  extern void *memmove(void *__dest, const void *__src, size_t __n)
    43  __THROW __nonnull((1, 2));
    44  
    45  /* Copy no more than N bytes of SRC to DEST, stopping when C is found.
    46     Return the position in DEST one byte past where C was copied,
    47     or NULL if C was not found in the first N bytes of SRC.  */
    48  #if defined __USE_MISC || defined __USE_XOPEN
    49  extern void *memccpy(void *__restrict __dest, const void *__restrict __src, int __c, size_t __n)
    50  __THROW __nonnull((1, 2));
    51  #endif				/* Misc || X/Open.  */
    52  
    53  /* Set N bytes of S to C.  */
    54  extern void *memset(void *__s, int __c, size_t __n)
    55  __THROW __nonnull((1));
    56  
    57  /* Compare N bytes of S1 and S2.  */
    58  extern int memcmp(const void *__s1, const void *__s2, size_t __n)
    59  __THROW __attribute_pure__ __nonnull((1, 2));
    60  
    61  /* Search N bytes of S for C.  */
    62  #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
    63  extern "C++" {
    64  	extern void *memchr(void *__s, int __c, size_t __n)
    65  	__THROW __asm("memchr") __attribute_pure__ __nonnull((1));
    66  	extern const void *memchr(const void *__s, int __c, size_t __n)
    67  	__THROW __asm("memchr") __attribute_pure__ __nonnull((1));
    68  
    69  # ifdef __OPTIMIZE__
    70  	__extern_always_inline void *memchr(void *__s, int __c, size_t __n) __THROW
    71  {
    72  	return __builtin_memchr(__s, __c, __n);
    73  } __extern_always_inline const void *memchr(const void *__s, int __c, size_t __n) __THROW {
    74  		return __builtin_memchr(__s, __c, __n);
    75  }
    76  # endif
    77  }
    78  #else
    79  extern void *memchr(const void *__s, int __c, size_t __n)
    80  __THROW __attribute_pure__ __nonnull((1));
    81  #endif
    82  
    83  #ifdef __USE_GNU
    84  /* Search in S for C.  This is similar to `memchr' but there is no
    85     length limit.  */
    86  # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
    87  extern "C++" void *rawmemchr(void *__s, int __c)
    88  __THROW __asm("rawmemchr")
    89  __attribute_pure__ __nonnull((1));
    90  extern "C++" const void *rawmemchr(const void *__s, int __c)
    91  __THROW __asm("rawmemchr")
    92  __attribute_pure__ __nonnull((1));
    93  # else
    94  extern void *rawmemchr(const void *__s, int __c)
    95  __THROW __attribute_pure__ __nonnull((1));
    96  # endif
    97  
    98  /* Search N bytes of S for the final occurrence of C.  */
    99  # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
   100  extern "C++" void *memrchr(void *__s, int __c, size_t __n)
   101  __THROW __asm("memrchr")
   102  __attribute_pure__ __nonnull((1));
   103  extern "C++" const void *memrchr(const void *__s, int __c, size_t __n)
   104  __THROW __asm("memrchr")
   105  __attribute_pure__ __nonnull((1));
   106  # else
   107  extern void *memrchr(const void *__s, int __c, size_t __n)
   108  __THROW __attribute_pure__ __nonnull((1));
   109  # endif
   110  #endif
   111  
   112  /* Copy SRC to DEST.  */
   113  extern char *strcpy(char *__restrict __dest, const char *__restrict __src)
   114  __THROW __nonnull((1, 2));
   115  /* Copy no more than N characters of SRC to DEST.  */
   116  extern char *strncpy(char *__restrict __dest, const char *__restrict __src, size_t __n)
   117  __THROW __nonnull((1, 2));
   118  
   119  /* Append SRC onto DEST.  */
   120  extern char *strcat(char *__restrict __dest, const char *__restrict __src)
   121  __THROW __nonnull((1, 2));
   122  /* Append no more than N characters from SRC onto DEST.  */
   123  extern char *strncat(char *__restrict __dest, const char *__restrict __src, size_t __n)
   124  __THROW __nonnull((1, 2));
   125  
   126  /* Compare S1 and S2.  */
   127  extern int strcmp(const char *__s1, const char *__s2)
   128  __THROW __attribute_pure__ __nonnull((1, 2));
   129  /* Compare N characters of S1 and S2.  */
   130  extern int strncmp(const char *__s1, const char *__s2, size_t __n)
   131  __THROW __attribute_pure__ __nonnull((1, 2));
   132  
   133  /* Compare the collated forms of S1 and S2.  */
   134  extern int strcoll(const char *__s1, const char *__s2)
   135  __THROW __attribute_pure__ __nonnull((1, 2));
   136  /* Put a transformation of SRC into no more than N bytes of DEST.  */
   137  extern size_t strxfrm(char *__restrict __dest, const char *__restrict __src, size_t __n)
   138  __THROW __nonnull((2));
   139  
   140  #ifdef __USE_XOPEN2K8
   141  /* POSIX.1-2008 extended locale interface (see locale.h).  */
   142  # include <bits/types/locale_t.h>
   143  
   144  /* Compare the collated forms of S1 and S2, using sorting rules from L.  */
   145  extern int strcoll_l(const char *__s1, const char *__s2, locale_t __l)
   146  __THROW __attribute_pure__ __nonnull((1, 2, 3));
   147  /* Put a transformation of SRC into no more than N bytes of DEST,
   148     using sorting rules from L.  */
   149  extern size_t strxfrm_l(char *__dest, const char *__src, size_t __n, locale_t __l)
   150  __THROW __nonnull((2, 4));
   151  #endif
   152  
   153  #if (defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8	\
   154       || __GLIBC_USE (LIB_EXT2))
   155  /* Duplicate S, returning an identical malloc'd string.  */
   156  extern char *strdup(const char *__s)
   157  __THROW __attribute_malloc__ __nonnull((1));
   158  #endif
   159  
   160  /* Return a malloc'd copy of at most N bytes of STRING.  The
   161     resultant string is terminated even if no null terminator
   162     appears before STRING[N].  */
   163  #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
   164  extern char *strndup(const char *__string, size_t __n)
   165  __THROW __attribute_malloc__ __nonnull((1));
   166  #endif
   167  
   168  #if defined __USE_GNU && defined __GNUC__
   169  /* Duplicate S, returning an identical alloca'd string.  */
   170  # define strdupa(s)							      \
   171    (__extension__							      \
   172      ({									      \
   173        const char *__old = (s);						      \
   174        size_t __len = strlen (__old) + 1;				      \
   175        char *__new = (char *) __builtin_alloca (__len);			      \
   176        (char *) memcpy (__new, __old, __len);				      \
   177      }))
   178  
   179  /* Return an alloca'd copy of at most N bytes of string.  */
   180  # define strndupa(s, n)							      \
   181    (__extension__							      \
   182      ({									      \
   183        const char *__old = (s);						      \
   184        size_t __len = strnlen (__old, (n));				      \
   185        char *__new = (char *) __builtin_alloca (__len + 1);		      \
   186        __new[__len] = '\0';						      \
   187        (char *) memcpy (__new, __old, __len);				      \
   188      }))
   189  #endif
   190  
   191  /* Find the first occurrence of C in S.  */
   192  #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
   193  extern "C++" {
   194  	extern char *strchr(char *__s, int __c)
   195  	__THROW __asm("strchr") __attribute_pure__ __nonnull((1));
   196  	extern const char *strchr(const char *__s, int __c)
   197  	__THROW __asm("strchr") __attribute_pure__ __nonnull((1));
   198  
   199  # ifdef __OPTIMIZE__
   200  	__extern_always_inline char *strchr(char *__s, int __c) __THROW
   201  {
   202  	return __builtin_strchr(__s, __c);
   203  } __extern_always_inline const char *strchr(const char *__s, int __c) __THROW {
   204  		return __builtin_strchr(__s, __c);
   205  }
   206  # endif
   207  }
   208  #else
   209  extern char *strchr(const char *__s, int __c)
   210  __THROW __attribute_pure__ __nonnull((1));
   211  #endif
   212  /* Find the last occurrence of C in S.  */
   213  #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
   214  extern "C++" {
   215  	extern char *strrchr(char *__s, int __c)
   216  	__THROW __asm("strrchr") __attribute_pure__ __nonnull((1));
   217  	extern const char *strrchr(const char *__s, int __c)
   218  	__THROW __asm("strrchr") __attribute_pure__ __nonnull((1));
   219  
   220  # ifdef __OPTIMIZE__
   221  	__extern_always_inline char *strrchr(char *__s, int __c) __THROW
   222  {
   223  	return __builtin_strrchr(__s, __c);
   224  } __extern_always_inline const char *strrchr(const char *__s, int __c) __THROW {
   225  		return __builtin_strrchr(__s, __c);
   226  }
   227  # endif
   228  }
   229  #else
   230  extern char *strrchr(const char *__s, int __c)
   231  __THROW __attribute_pure__ __nonnull((1));
   232  #endif
   233  
   234  #ifdef __USE_GNU
   235  /* This function is similar to `strchr'.  But it returns a pointer to
   236     the closing NUL byte in case C is not found in S.  */
   237  # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
   238  extern "C++" char *strchrnul(char *__s, int __c)
   239  __THROW __asm("strchrnul")
   240  __attribute_pure__ __nonnull((1));
   241  extern "C++" const char *strchrnul(const char *__s, int __c)
   242  __THROW __asm("strchrnul")
   243  __attribute_pure__ __nonnull((1));
   244  # else
   245  extern char *strchrnul(const char *__s, int __c)
   246  __THROW __attribute_pure__ __nonnull((1));
   247  # endif
   248  #endif
   249  
   250  /* Return the length of the initial segment of S which
   251     consists entirely of characters not in REJECT.  */
   252  extern size_t strcspn(const char *__s, const char *__reject)
   253  __THROW __attribute_pure__ __nonnull((1, 2));
   254  /* Return the length of the initial segment of S which
   255     consists entirely of characters in ACCEPT.  */
   256  extern size_t strspn(const char *__s, const char *__accept)
   257  __THROW __attribute_pure__ __nonnull((1, 2));
   258  /* Find the first occurrence in S of any character in ACCEPT.  */
   259  #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
   260  extern "C++" {
   261  	extern char *strpbrk(char *__s, const char *__accept)
   262  	__THROW __asm("strpbrk") __attribute_pure__ __nonnull((1, 2));
   263  	extern const char *strpbrk(const char *__s, const char *__accept)
   264  	__THROW __asm("strpbrk") __attribute_pure__ __nonnull((1, 2));
   265  
   266  # ifdef __OPTIMIZE__
   267  	__extern_always_inline char *strpbrk(char *__s, const char *__accept) __THROW
   268  {
   269  	return __builtin_strpbrk(__s, __accept);
   270  } __extern_always_inline const char *strpbrk(const char *__s, const char *__accept) __THROW {
   271  		return __builtin_strpbrk(__s, __accept);
   272  }
   273  # endif
   274  }
   275  #else
   276  extern char *strpbrk(const char *__s, const char *__accept)
   277  __THROW __attribute_pure__ __nonnull((1, 2));
   278  #endif
   279  /* Find the first occurrence of NEEDLE in HAYSTACK.  */
   280  #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
   281  extern "C++" {
   282  	extern char *strstr(char *__haystack, const char *__needle)
   283  	__THROW __asm("strstr") __attribute_pure__ __nonnull((1, 2));
   284  	extern const char *strstr(const char *__haystack, const char *__needle)
   285  	__THROW __asm("strstr") __attribute_pure__ __nonnull((1, 2));
   286  
   287  # ifdef __OPTIMIZE__
   288  	__extern_always_inline char *strstr(char *__haystack, const char *__needle) __THROW
   289  {
   290  	return __builtin_strstr(__haystack, __needle);
   291  } __extern_always_inline const char *strstr(const char *__haystack, const char *__needle) __THROW {
   292  		return __builtin_strstr(__haystack, __needle);
   293  }
   294  # endif
   295  }
   296  #else
   297  extern char *strstr(const char *__haystack, const char *__needle)
   298  __THROW __attribute_pure__ __nonnull((1, 2));
   299  #endif
   300  
   301  /* Divide S into tokens separated by characters in DELIM.  */
   302  extern char *strtok(char *__restrict __s, const char *__restrict __delim)
   303  __THROW __nonnull((2));
   304  
   305  /* Divide S into tokens separated by characters in DELIM.  Information
   306     passed between calls are stored in SAVE_PTR.  */
   307  extern char *__strtok_r(char *__restrict __s, const char *__restrict __delim, char **__restrict __save_ptr)
   308  __THROW __nonnull((2, 3));
   309  #ifdef __USE_POSIX
   310  extern char *strtok_r(char *__restrict __s, const char *__restrict __delim, char **__restrict __save_ptr)
   311  __THROW __nonnull((2, 3));
   312  #endif
   313  
   314  #ifdef __USE_GNU
   315  /* Similar to `strstr' but this function ignores the case of both strings.  */
   316  # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
   317  extern "C++" char *strcasestr(char *__haystack, const char *__needle)
   318  __THROW __asm("strcasestr")
   319  __attribute_pure__ __nonnull((1, 2));
   320  extern "C++" const char *strcasestr(const char *__haystack, const char *__needle)
   321  __THROW __asm("strcasestr")
   322  __attribute_pure__ __nonnull((1, 2));
   323  # else
   324  extern char *strcasestr(const char *__haystack, const char *__needle)
   325  __THROW __attribute_pure__ __nonnull((1, 2));
   326  # endif
   327  #endif
   328  
   329  #ifdef __USE_GNU
   330  /* Find the first occurrence of NEEDLE in HAYSTACK.
   331     NEEDLE is NEEDLELEN bytes long;
   332     HAYSTACK is HAYSTACKLEN bytes long.  */
   333  extern void *memmem(const void *__haystack, size_t __haystacklen, const void *__needle, size_t __needlelen)
   334  __THROW __attribute_pure__ __nonnull((1, 3));
   335  
   336  /* Copy N bytes of SRC to DEST, return pointer to bytes after the
   337     last written byte.  */
   338  extern void *__mempcpy(void *__restrict __dest, const void *__restrict __src, size_t __n)
   339  __THROW __nonnull((1, 2));
   340  extern void *mempcpy(void *__restrict __dest, const void *__restrict __src, size_t __n)
   341  __THROW __nonnull((1, 2));
   342  #endif
   343  
   344  /* Return the length of S.  */
   345  extern size_t strlen(const char *__s)
   346  __THROW __attribute_pure__ __nonnull((1));
   347  
   348  #ifdef	__USE_XOPEN2K8
   349  /* Find the length of STRING, but scan at most MAXLEN characters.
   350     If no '\0' terminator is found in that many characters, return MAXLEN.  */
   351  extern size_t strnlen(const char *__string, size_t __maxlen)
   352  __THROW __attribute_pure__ __nonnull((1));
   353  #endif
   354  
   355  /* Return a string describing the meaning of the `errno' code in ERRNUM.  */
   356  extern char *strerror(int __errnum) __THROW;
   357  #ifdef __USE_XOPEN2K
   358  /* Reentrant version of `strerror'.
   359     There are 2 flavors of `strerror_r', GNU which returns the string
   360     and may or may not use the supplied temporary buffer and POSIX one
   361     which fills the string into the buffer.
   362     To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L
   363     without -D_GNU_SOURCE is needed, otherwise the GNU version is
   364     preferred.  */
   365  # if defined __USE_XOPEN2K && !defined __USE_GNU
   366  /* Fill BUF with a string describing the meaning of the `errno' code in
   367     ERRNUM.  */
   368  #  ifdef __REDIRECT_NTH
   369  extern int __REDIRECT_NTH(strerror_r, (int __errnum, char *__buf, size_t __buflen), __xpg_strerror_r) __nonnull((2));
   370  #  else
   371  extern int __xpg_strerror_r(int __errnum, char *__buf, size_t __buflen)
   372  __THROW __nonnull((2));
   373  #   define strerror_r __xpg_strerror_r
   374  #  endif
   375  # else
   376  /* If a temporary buffer is required, at most BUFLEN bytes of BUF will be
   377     used.  */
   378  extern char *strerror_r(int __errnum, char *__buf, size_t __buflen)
   379  __THROW __nonnull((2)) __wur;
   380  # endif
   381  #endif
   382  
   383  #ifdef __USE_XOPEN2K8
   384  /* Translate error number to string according to the locale L.  */
   385  extern char *strerror_l(int __errnum, locale_t __l) __THROW;
   386  #endif
   387  
   388  #ifdef __USE_MISC
   389  # include <strings.h>
   390  
   391  /* Set N bytes of S to 0.  The compiler will not delete a call to this
   392     function, even if S is dead after the call.  */
   393  extern void explicit_bzero(void *__s, size_t __n)
   394  __THROW __nonnull((1));
   395  
   396  /* Return the next DELIM-delimited token from *STRINGP,
   397     terminating it with a '\0', and update *STRINGP to point past it.  */
   398  extern char *strsep(char **__restrict __stringp, const char *__restrict __delim)
   399  __THROW __nonnull((1, 2));
   400  #endif
   401  
   402  #ifdef	__USE_XOPEN2K8
   403  /* Return a string describing the meaning of the signal number in SIG.  */
   404  extern char *strsignal(int __sig) __THROW;
   405  
   406  /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST.  */
   407  extern char *__stpcpy(char *__restrict __dest, const char *__restrict __src)
   408  __THROW __nonnull((1, 2));
   409  extern char *stpcpy(char *__restrict __dest, const char *__restrict __src)
   410  __THROW __nonnull((1, 2));
   411  
   412  /* Copy no more than N characters of SRC to DEST, returning the address of
   413     the last character written into DEST.  */
   414  extern char *__stpncpy(char *__restrict __dest, const char *__restrict __src, size_t __n)
   415  __THROW __nonnull((1, 2));
   416  extern char *stpncpy(char *__restrict __dest, const char *__restrict __src, size_t __n)
   417  __THROW __nonnull((1, 2));
   418  #endif
   419  
   420  #ifdef	__USE_GNU
   421  /* Compare S1 and S2 as strings holding name & indices/version numbers.  */
   422  extern int strverscmp(const char *__s1, const char *__s2)
   423  __THROW __attribute_pure__ __nonnull((1, 2));
   424  
   425  /* Sautee STRING briskly.  */
   426  extern char *strfry(char *__string)
   427  __THROW __nonnull((1));
   428  
   429  /* Frobnicate N bytes of S.  */
   430  extern void *memfrob(void *__s, size_t __n)
   431  __THROW __nonnull((1));
   432  
   433  # ifndef basename
   434  /* Return the file name within directory of FILENAME.  We don't
   435     declare the function if the `basename' macro is available (defined
   436     in <libgen.h>) which makes the XPG version of this function
   437     available.  */
   438  #  ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
   439  extern "C++" char *basename(char *__filename)
   440  __THROW __asm("basename") __nonnull((1));
   441  extern "C++" const char *basename(const char *__filename)
   442  __THROW __asm("basename") __nonnull((1));
   443  #  else
   444  extern char *basename(const char *__filename)
   445  __THROW __nonnull((1));
   446  #  endif
   447  # endif
   448  #endif
   449  
   450  #if __GNUC_PREREQ (3,4)
   451  # if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
   452  /* Functions with security checks.  */
   453  #  include <bits/string_fortified.h>
   454  # endif
   455  #endif
   456  
   457  __END_DECLS
   458  #endif				/* string.h  */