X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstring.in.h;h=7d508ccdf5d5e94808e884261a34ca418e50122e;hb=159eae9ff30acac95b6d397f053df8cd6fca62a3;hp=c60e2f31600e8c30a7d10929e38e08e941d4ebc7;hpb=a8c5982a27c78c9da038f1520c43a948e4d50e48;p=gnulib.git diff --git a/lib/string.in.h b/lib/string.in.h index c60e2f316..7d508ccdf 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 1995-1996, 2001-2007 Free Software Foundation, Inc. + Copyright (C) 1995-1996, 2001-2008 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,6 +18,10 @@ #ifndef _GL_STRING_H +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif + /* The include_next requires a split double-inclusion guard. */ #@INCLUDE_NEXT@ @NEXT_STRING_H@ @@ -25,6 +29,18 @@ #define _GL_STRING_H +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +# define __attribute__(Spec) /* empty */ +# endif +/* The attribute __pure__ was added in gcc 2.96. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) +# define __pure__ /* empty */ +# endif +#endif + + /* The definition of GL_LINK_WARNING is copied here. */ @@ -35,15 +51,20 @@ extern "C" { /* Return the first occurrence of NEEDLE in HAYSTACK. */ #if @GNULIB_MEMMEM@ -# if ! @HAVE_DECL_MEMMEM@ +# if @REPLACE_MEMMEM@ +# define memmem rpl_memmem +# endif +# if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@ extern void *memmem (void const *__haystack, size_t __haystack_len, - void const *__needle, size_t __needle_len); + void const *__needle, size_t __needle_len) + __attribute__ ((__pure__)); # endif #elif defined GNULIB_POSIXCHECK # undef memmem # define memmem(a,al,b,bl) \ - (GL_LINK_WARNING ("memmem is unportable - " \ - "use gnulib module memmem for portability"), \ + (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \ + "use gnulib module memmem-simple for portability, " \ + "and module memmem for speed" ), \ memmem (a, al, b, bl)) #endif @@ -65,7 +86,8 @@ extern void *mempcpy (void *restrict __dest, void const *restrict __src, /* Search backwards through a block for a byte (specified as an int). */ #if @GNULIB_MEMRCHR@ # if ! @HAVE_DECL_MEMRCHR@ -extern void *memrchr (void const *, int, size_t); +extern void *memrchr (void const *, int, size_t) + __attribute__ ((__pure__)); # endif #elif defined GNULIB_POSIXCHECK # undef memrchr @@ -75,6 +97,22 @@ extern void *memrchr (void const *, int, size_t); memrchr (a, b, c)) #endif +/* Find the first occurrence of C in S. More efficient than + memchr(S,C,N), at the expense of undefined behavior if C does not + occur within N bytes. */ +#if @GNULIB_RAWMEMCHR@ +# if ! @HAVE_RAWMEMCHR@ +extern void *rawmemchr (void const *__s, int __c_in) + __attribute__ ((__pure__)); +# endif +#elif defined GNULIB_POSIXCHECK +# undef rawmemchr +# define rawmemchr(a,b) \ + (GL_LINK_WARNING ("rawmemchr is unportable - " \ + "use gnulib module rawmemchr for portability"), \ + rawmemchr (a, b)) +#endif + /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ #if @GNULIB_STPCPY@ # if ! @HAVE_STPCPY@ @@ -118,7 +156,8 @@ extern char *stpncpy (char *restrict __dst, char const *restrict __src, /* Find the first occurrence of C in S or the final NUL byte. */ #if @GNULIB_STRCHRNUL@ # if ! @HAVE_STRCHRNUL@ -extern char *strchrnul (char const *__s, int __c_in); +extern char *strchrnul (char const *__s, int __c_in) + __attribute__ ((__pure__)); # endif #elif defined GNULIB_POSIXCHECK # undef strchrnul @@ -130,7 +169,11 @@ extern char *strchrnul (char const *__s, int __c_in); /* Duplicate S, returning an identical malloc'd string. */ #if @GNULIB_STRDUP@ -# if ! @HAVE_DECL_STRDUP@ && ! defined strdup +# if @REPLACE_STRDUP@ +# undef strdup +# define strdup rpl_strdup +# endif +# if !(@HAVE_DECL_STRDUP@ || defined strdup) || @REPLACE_STRDUP@ extern char *strdup (char const *__s); # endif #elif defined GNULIB_POSIXCHECK @@ -163,7 +206,8 @@ extern char *strndup (char const *__string, size_t __n); return MAXLEN. */ #if @GNULIB_STRNLEN@ # if ! @HAVE_DECL_STRNLEN@ -extern size_t strnlen (char const *__string, size_t __maxlen); +extern size_t strnlen (char const *__string, size_t __maxlen) + __attribute__ ((__pure__)); # endif #elif defined GNULIB_POSIXCHECK # undef strnlen @@ -189,7 +233,8 @@ extern size_t strnlen (char const *__string, size_t __maxlen); /* Find the first occurrence in S of any character in ACCEPT. */ #if @GNULIB_STRPBRK@ # if ! @HAVE_STRPBRK@ -extern char *strpbrk (char const *__s, char const *__accept); +extern char *strpbrk (char const *__s, char const *__accept) + __attribute__ ((__pure__)); # endif # if defined GNULIB_POSIXCHECK /* strpbrk() assumes the second argument is a list of single-byte characters. @@ -269,25 +314,38 @@ extern char *strsep (char **restrict __stringp, char const *restrict __delim); strsep (s, d)) #endif -#if defined GNULIB_POSIXCHECK +#if @GNULIB_STRSTR@ +# if @REPLACE_STRSTR@ +# define strstr rpl_strstr +char *strstr (const char *haystack, const char *needle) + __attribute__ ((__pure__)); +# endif +#elif defined GNULIB_POSIXCHECK /* strstr() does not work with multibyte strings if the locale encoding is different from UTF-8: POSIX says that it operates on "strings", and "string" in POSIX is defined as a sequence of bytes, not of characters. */ # undef strstr # define strstr(a,b) \ - (GL_LINK_WARNING ("strstr cannot work correctly on character strings " \ - "in most multibyte locales - " \ - "use mbsstr if you care about internationalization"), \ + (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \ + "work correctly on character strings in most " \ + "multibyte locales - " \ + "use mbsstr if you care about internationalization, " \ + "or use strstr if you care about speed"), \ strstr (a, b)) #endif /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive comparison. */ -#if ! @HAVE_STRCASESTR@ -extern char *strcasestr (const char *haystack, const char *needle); -#endif -#if defined GNULIB_POSIXCHECK +#if @GNULIB_STRCASESTR@ +# if @REPLACE_STRCASESTR@ +# define strcasestr rpl_strcasestr +# endif +# if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@ +extern char *strcasestr (const char *haystack, const char *needle) + __attribute__ ((__pure__)); +# endif +#elif defined GNULIB_POSIXCHECK /* strcasestr() does not work with multibyte strings: It is a glibc extension, and glibc implements it only for unibyte locales. */ @@ -511,6 +569,33 @@ extern char *strerror (int); strerror (e)) #endif +#if @GNULIB_STRSIGNAL@ +# if @REPLACE_STRSIGNAL@ +# define strsignal rpl_strsignal +# endif +# if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@ +extern char *strsignal (int __sig); +# endif +#elif defined GNULIB_POSIXCHECK +# undef strsignal +# define strsignal(a) \ + (GL_LINK_WARNING ("strsignal is unportable - " \ + "use gnulib module strsignal for portability"), \ + strsignal (a)) +#endif + +#if @GNULIB_STRVERSCMP@ +# if !@HAVE_STRVERSCMP@ +extern int strverscmp (const char *, const char *); +# endif +#elif defined GNULIB_POSIXCHECK +# undef strverscmp +# define strverscmp(a, b) \ + (GL_LINK_WARNING ("strverscmp is unportable - " \ + "use gnulib module strverscmp for portability"), \ + strverscmp (a, b)) +#endif + #ifdef __cplusplus }