diff options
| author | Joakim Verona | 2013-02-13 00:04:17 +0100 |
|---|---|---|
| committer | Joakim Verona | 2013-02-13 00:04:17 +0100 |
| commit | e46029ad6dda065541c8de40de0fe9d5800ac770 (patch) | |
| tree | 891ff36967b0ef02459ee46b6363b75bf810d524 /lib | |
| parent | e0444a0966fa001953bb97cfb60451c42220be8e (diff) | |
| parent | c4131562319d3529841136d236ac39fb1e3d2b7c (diff) | |
| download | emacs-e46029ad6dda065541c8de40de0fe9d5800ac770.tar.gz emacs-e46029ad6dda065541c8de40de0fe9d5800ac770.zip | |
auto upstream
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/gnulib.mk | 111 | ||||
| -rw-r--r-- | lib/makefile.w32-in | 5 | ||||
| -rw-r--r-- | lib/memrchr.c | 161 | ||||
| -rw-r--r-- | lib/stdlib.in.h | 2 | ||||
| -rw-r--r-- | lib/string.in.h | 1029 | ||||
| -rw-r--r-- | lib/unsetenv.c | 4 |
6 files changed, 1308 insertions, 4 deletions
diff --git a/lib/gnulib.mk b/lib/gnulib.mk index 8103eec88a0..c130cbc65b8 100644 --- a/lib/gnulib.mk +++ b/lib/gnulib.mk | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | # the same distribution terms as the rest of that program. | 21 | # the same distribution terms as the rest of that program. |
| 22 | # | 22 | # |
| 23 | # Generated by gnulib-tool. | 23 | # Generated by gnulib-tool. |
| 24 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=dup --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h fdopendir filemode fstatat getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask putenv readlink readlinkat sig2str socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub unsetenv utimens warnings | 24 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=dup --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h fdopendir filemode fstatat getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings memrchr mktime pselect pthread_sigmask putenv readlink readlinkat sig2str socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub unsetenv utimens warnings |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | MOSTLYCLEANFILES += core *.stackdump | 27 | MOSTLYCLEANFILES += core *.stackdump |
| @@ -480,6 +480,15 @@ EXTRA_libgnu_a_SOURCES += lstat.c | |||
| 480 | 480 | ||
| 481 | ## end gnulib module lstat | 481 | ## end gnulib module lstat |
| 482 | 482 | ||
| 483 | ## begin gnulib module memrchr | ||
| 484 | |||
| 485 | |||
| 486 | EXTRA_DIST += memrchr.c | ||
| 487 | |||
| 488 | EXTRA_libgnu_a_SOURCES += memrchr.c | ||
| 489 | |||
| 490 | ## end gnulib module memrchr | ||
| 491 | |||
| 483 | ## begin gnulib module mktime | 492 | ## begin gnulib module mktime |
| 484 | 493 | ||
| 485 | 494 | ||
| @@ -1105,6 +1114,106 @@ EXTRA_DIST += strftime.h | |||
| 1105 | 1114 | ||
| 1106 | ## end gnulib module strftime | 1115 | ## end gnulib module strftime |
| 1107 | 1116 | ||
| 1117 | ## begin gnulib module string | ||
| 1118 | |||
| 1119 | BUILT_SOURCES += string.h | ||
| 1120 | |||
| 1121 | # We need the following in order to create <string.h> when the system | ||
| 1122 | # doesn't have one that works with the given compiler. | ||
| 1123 | string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) | ||
| 1124 | $(AM_V_GEN)rm -f $@-t $@ && \ | ||
| 1125 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ | ||
| 1126 | sed -e 's|@''GUARD_PREFIX''@|GL|g' \ | ||
| 1127 | -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ | ||
| 1128 | -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ | ||
| 1129 | -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ | ||
| 1130 | -e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \ | ||
| 1131 | -e 's/@''GNULIB_FFSL''@/$(GNULIB_FFSL)/g' \ | ||
| 1132 | -e 's/@''GNULIB_FFSLL''@/$(GNULIB_FFSLL)/g' \ | ||
| 1133 | -e 's/@''GNULIB_MBSLEN''@/$(GNULIB_MBSLEN)/g' \ | ||
| 1134 | -e 's/@''GNULIB_MBSNLEN''@/$(GNULIB_MBSNLEN)/g' \ | ||
| 1135 | -e 's/@''GNULIB_MBSCHR''@/$(GNULIB_MBSCHR)/g' \ | ||
| 1136 | -e 's/@''GNULIB_MBSRCHR''@/$(GNULIB_MBSRCHR)/g' \ | ||
| 1137 | -e 's/@''GNULIB_MBSSTR''@/$(GNULIB_MBSSTR)/g' \ | ||
| 1138 | -e 's/@''GNULIB_MBSCASECMP''@/$(GNULIB_MBSCASECMP)/g' \ | ||
| 1139 | -e 's/@''GNULIB_MBSNCASECMP''@/$(GNULIB_MBSNCASECMP)/g' \ | ||
| 1140 | -e 's/@''GNULIB_MBSPCASECMP''@/$(GNULIB_MBSPCASECMP)/g' \ | ||
| 1141 | -e 's/@''GNULIB_MBSCASESTR''@/$(GNULIB_MBSCASESTR)/g' \ | ||
| 1142 | -e 's/@''GNULIB_MBSCSPN''@/$(GNULIB_MBSCSPN)/g' \ | ||
| 1143 | -e 's/@''GNULIB_MBSPBRK''@/$(GNULIB_MBSPBRK)/g' \ | ||
| 1144 | -e 's/@''GNULIB_MBSSPN''@/$(GNULIB_MBSSPN)/g' \ | ||
| 1145 | -e 's/@''GNULIB_MBSSEP''@/$(GNULIB_MBSSEP)/g' \ | ||
| 1146 | -e 's/@''GNULIB_MBSTOK_R''@/$(GNULIB_MBSTOK_R)/g' \ | ||
| 1147 | -e 's/@''GNULIB_MEMCHR''@/$(GNULIB_MEMCHR)/g' \ | ||
| 1148 | -e 's/@''GNULIB_MEMMEM''@/$(GNULIB_MEMMEM)/g' \ | ||
| 1149 | -e 's/@''GNULIB_MEMPCPY''@/$(GNULIB_MEMPCPY)/g' \ | ||
| 1150 | -e 's/@''GNULIB_MEMRCHR''@/$(GNULIB_MEMRCHR)/g' \ | ||
| 1151 | -e 's/@''GNULIB_RAWMEMCHR''@/$(GNULIB_RAWMEMCHR)/g' \ | ||
| 1152 | -e 's/@''GNULIB_STPCPY''@/$(GNULIB_STPCPY)/g' \ | ||
| 1153 | -e 's/@''GNULIB_STPNCPY''@/$(GNULIB_STPNCPY)/g' \ | ||
| 1154 | -e 's/@''GNULIB_STRCHRNUL''@/$(GNULIB_STRCHRNUL)/g' \ | ||
| 1155 | -e 's/@''GNULIB_STRDUP''@/$(GNULIB_STRDUP)/g' \ | ||
| 1156 | -e 's/@''GNULIB_STRNCAT''@/$(GNULIB_STRNCAT)/g' \ | ||
| 1157 | -e 's/@''GNULIB_STRNDUP''@/$(GNULIB_STRNDUP)/g' \ | ||
| 1158 | -e 's/@''GNULIB_STRNLEN''@/$(GNULIB_STRNLEN)/g' \ | ||
| 1159 | -e 's/@''GNULIB_STRPBRK''@/$(GNULIB_STRPBRK)/g' \ | ||
| 1160 | -e 's/@''GNULIB_STRSEP''@/$(GNULIB_STRSEP)/g' \ | ||
| 1161 | -e 's/@''GNULIB_STRSTR''@/$(GNULIB_STRSTR)/g' \ | ||
| 1162 | -e 's/@''GNULIB_STRCASESTR''@/$(GNULIB_STRCASESTR)/g' \ | ||
| 1163 | -e 's/@''GNULIB_STRTOK_R''@/$(GNULIB_STRTOK_R)/g' \ | ||
| 1164 | -e 's/@''GNULIB_STRERROR''@/$(GNULIB_STRERROR)/g' \ | ||
| 1165 | -e 's/@''GNULIB_STRERROR_R''@/$(GNULIB_STRERROR_R)/g' \ | ||
| 1166 | -e 's/@''GNULIB_STRSIGNAL''@/$(GNULIB_STRSIGNAL)/g' \ | ||
| 1167 | -e 's/@''GNULIB_STRVERSCMP''@/$(GNULIB_STRVERSCMP)/g' \ | ||
| 1168 | < $(srcdir)/string.in.h | \ | ||
| 1169 | sed -e 's|@''HAVE_FFSL''@|$(HAVE_FFSL)|g' \ | ||
| 1170 | -e 's|@''HAVE_FFSLL''@|$(HAVE_FFSLL)|g' \ | ||
| 1171 | -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \ | ||
| 1172 | -e 's|@''HAVE_MEMCHR''@|$(HAVE_MEMCHR)|g' \ | ||
| 1173 | -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \ | ||
| 1174 | -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \ | ||
| 1175 | -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \ | ||
| 1176 | -e 's|@''HAVE_RAWMEMCHR''@|$(HAVE_RAWMEMCHR)|g' \ | ||
| 1177 | -e 's|@''HAVE_STPCPY''@|$(HAVE_STPCPY)|g' \ | ||
| 1178 | -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \ | ||
| 1179 | -e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \ | ||
| 1180 | -e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \ | ||
| 1181 | -e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \ | ||
| 1182 | -e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \ | ||
| 1183 | -e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \ | ||
| 1184 | -e 's|@''HAVE_STRSEP''@|$(HAVE_STRSEP)|g' \ | ||
| 1185 | -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \ | ||
| 1186 | -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ | ||
| 1187 | -e 's|@''HAVE_DECL_STRERROR_R''@|$(HAVE_DECL_STRERROR_R)|g' \ | ||
| 1188 | -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ | ||
| 1189 | -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ | ||
| 1190 | -e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \ | ||
| 1191 | -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \ | ||
| 1192 | -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \ | ||
| 1193 | -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \ | ||
| 1194 | -e 's|@''REPLACE_STRCHRNUL''@|$(REPLACE_STRCHRNUL)|g' \ | ||
| 1195 | -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \ | ||
| 1196 | -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \ | ||
| 1197 | -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ | ||
| 1198 | -e 's|@''REPLACE_STRERROR_R''@|$(REPLACE_STRERROR_R)|g' \ | ||
| 1199 | -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \ | ||
| 1200 | -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \ | ||
| 1201 | -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \ | ||
| 1202 | -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ | ||
| 1203 | -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ | ||
| 1204 | -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \ | ||
| 1205 | -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ | ||
| 1206 | -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ | ||
| 1207 | -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ | ||
| 1208 | < $(srcdir)/string.in.h; \ | ||
| 1209 | } > $@-t && \ | ||
| 1210 | mv $@-t $@ | ||
| 1211 | MOSTLYCLEANFILES += string.h string.h-t | ||
| 1212 | |||
| 1213 | EXTRA_DIST += string.in.h | ||
| 1214 | |||
| 1215 | ## end gnulib module string | ||
| 1216 | |||
| 1108 | ## begin gnulib module strtoimax | 1217 | ## begin gnulib module strtoimax |
| 1109 | 1218 | ||
| 1110 | 1219 | ||
diff --git a/lib/makefile.w32-in b/lib/makefile.w32-in index d5128cc9a61..cd62fbcd13d 100644 --- a/lib/makefile.w32-in +++ b/lib/makefile.w32-in | |||
| @@ -34,6 +34,7 @@ GNULIBOBJS = $(BLD)/c-ctype.$(O) \ | |||
| 34 | $(BLD)/getopt.$(O) \ | 34 | $(BLD)/getopt.$(O) \ |
| 35 | $(BLD)/getopt1.$(O) \ | 35 | $(BLD)/getopt1.$(O) \ |
| 36 | $(BLD)/gettime.$(O) \ | 36 | $(BLD)/gettime.$(O) \ |
| 37 | $(BLD)/memrchr.$(O) \ | ||
| 37 | $(BLD)/strftime.$(O) \ | 38 | $(BLD)/strftime.$(O) \ |
| 38 | $(BLD)/time_r.$(O) \ | 39 | $(BLD)/time_r.$(O) \ |
| 39 | $(BLD)/timespec-add.$(O) \ | 40 | $(BLD)/timespec-add.$(O) \ |
| @@ -201,6 +202,10 @@ $(BLD)/md5.$(O) : \ | |||
| 201 | $(CONFIG_H) \ | 202 | $(CONFIG_H) \ |
| 202 | $(MD5_H) | 203 | $(MD5_H) |
| 203 | 204 | ||
| 205 | $(BLD)/memrchr.$(O) : \ | ||
| 206 | $(GNU_LIB)/memrchr.c \ | ||
| 207 | $(CONFIG_H) | ||
| 208 | |||
| 204 | $(BLD)/sha1.$(O) : \ | 209 | $(BLD)/sha1.$(O) : \ |
| 205 | $(GNU_LIB)/sha1.c \ | 210 | $(GNU_LIB)/sha1.c \ |
| 206 | $(NT_INC)/stdalign.h \ | 211 | $(NT_INC)/stdalign.h \ |
diff --git a/lib/memrchr.c b/lib/memrchr.c new file mode 100644 index 00000000000..5a023e0638a --- /dev/null +++ b/lib/memrchr.c | |||
| @@ -0,0 +1,161 @@ | |||
| 1 | /* memrchr -- find the last occurrence of a byte in a memory block | ||
| 2 | |||
| 3 | Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2013 Free Software | ||
| 4 | Foundation, Inc. | ||
| 5 | |||
| 6 | Based on strlen implementation by Torbjorn Granlund (tege@sics.se), | ||
| 7 | with help from Dan Sahlin (dan@sics.se) and | ||
| 8 | commentary by Jim Blandy (jimb@ai.mit.edu); | ||
| 9 | adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu), | ||
| 10 | and implemented by Roland McGrath (roland@ai.mit.edu). | ||
| 11 | |||
| 12 | This program is free software: you can redistribute it and/or modify | ||
| 13 | it under the terms of the GNU General Public License as published by | ||
| 14 | the Free Software Foundation; either version 3 of the License, or | ||
| 15 | (at your option) any later version. | ||
| 16 | |||
| 17 | This program is distributed in the hope that it will be useful, | ||
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 20 | GNU General Public License for more details. | ||
| 21 | |||
| 22 | You should have received a copy of the GNU General Public License | ||
| 23 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 24 | |||
| 25 | #if defined _LIBC | ||
| 26 | # include <memcopy.h> | ||
| 27 | #else | ||
| 28 | # include <config.h> | ||
| 29 | # define reg_char char | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #include <string.h> | ||
| 33 | #include <limits.h> | ||
| 34 | |||
| 35 | #undef __memrchr | ||
| 36 | #ifdef _LIBC | ||
| 37 | # undef memrchr | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #ifndef weak_alias | ||
| 41 | # define __memrchr memrchr | ||
| 42 | #endif | ||
| 43 | |||
| 44 | /* Search no more than N bytes of S for C. */ | ||
| 45 | void * | ||
| 46 | __memrchr (void const *s, int c_in, size_t n) | ||
| 47 | { | ||
| 48 | /* On 32-bit hardware, choosing longword to be a 32-bit unsigned | ||
| 49 | long instead of a 64-bit uintmax_t tends to give better | ||
| 50 | performance. On 64-bit hardware, unsigned long is generally 64 | ||
| 51 | bits already. Change this typedef to experiment with | ||
| 52 | performance. */ | ||
| 53 | typedef unsigned long int longword; | ||
| 54 | |||
| 55 | const unsigned char *char_ptr; | ||
| 56 | const longword *longword_ptr; | ||
| 57 | longword repeated_one; | ||
| 58 | longword repeated_c; | ||
| 59 | unsigned reg_char c; | ||
| 60 | |||
| 61 | c = (unsigned char) c_in; | ||
| 62 | |||
| 63 | /* Handle the last few bytes by reading one byte at a time. | ||
| 64 | Do this until CHAR_PTR is aligned on a longword boundary. */ | ||
| 65 | for (char_ptr = (const unsigned char *) s + n; | ||
| 66 | n > 0 && (size_t) char_ptr % sizeof (longword) != 0; | ||
| 67 | --n) | ||
| 68 | if (*--char_ptr == c) | ||
| 69 | return (void *) char_ptr; | ||
| 70 | |||
| 71 | longword_ptr = (const longword *) char_ptr; | ||
| 72 | |||
| 73 | /* All these elucidatory comments refer to 4-byte longwords, | ||
| 74 | but the theory applies equally well to any size longwords. */ | ||
| 75 | |||
| 76 | /* Compute auxiliary longword values: | ||
| 77 | repeated_one is a value which has a 1 in every byte. | ||
| 78 | repeated_c has c in every byte. */ | ||
| 79 | repeated_one = 0x01010101; | ||
| 80 | repeated_c = c | (c << 8); | ||
| 81 | repeated_c |= repeated_c << 16; | ||
| 82 | if (0xffffffffU < (longword) -1) | ||
| 83 | { | ||
| 84 | repeated_one |= repeated_one << 31 << 1; | ||
| 85 | repeated_c |= repeated_c << 31 << 1; | ||
| 86 | if (8 < sizeof (longword)) | ||
| 87 | { | ||
| 88 | size_t i; | ||
| 89 | |||
| 90 | for (i = 64; i < sizeof (longword) * 8; i *= 2) | ||
| 91 | { | ||
| 92 | repeated_one |= repeated_one << i; | ||
| 93 | repeated_c |= repeated_c << i; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | /* Instead of the traditional loop which tests each byte, we will test a | ||
| 99 | longword at a time. The tricky part is testing if *any of the four* | ||
| 100 | bytes in the longword in question are equal to c. We first use an xor | ||
| 101 | with repeated_c. This reduces the task to testing whether *any of the | ||
| 102 | four* bytes in longword1 is zero. | ||
| 103 | |||
| 104 | We compute tmp = | ||
| 105 | ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). | ||
| 106 | That is, we perform the following operations: | ||
| 107 | 1. Subtract repeated_one. | ||
| 108 | 2. & ~longword1. | ||
| 109 | 3. & a mask consisting of 0x80 in every byte. | ||
| 110 | Consider what happens in each byte: | ||
| 111 | - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, | ||
| 112 | and step 3 transforms it into 0x80. A carry can also be propagated | ||
| 113 | to more significant bytes. | ||
| 114 | - If a byte of longword1 is nonzero, let its lowest 1 bit be at | ||
| 115 | position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, | ||
| 116 | the byte ends in a single bit of value 0 and k bits of value 1. | ||
| 117 | After step 2, the result is just k bits of value 1: 2^k - 1. After | ||
| 118 | step 3, the result is 0. And no carry is produced. | ||
| 119 | So, if longword1 has only non-zero bytes, tmp is zero. | ||
| 120 | Whereas if longword1 has a zero byte, call j the position of the least | ||
| 121 | significant zero byte. Then the result has a zero at positions 0, ..., | ||
| 122 | j-1 and a 0x80 at position j. We cannot predict the result at the more | ||
| 123 | significant bytes (positions j+1..3), but it does not matter since we | ||
| 124 | already have a non-zero bit at position 8*j+7. | ||
| 125 | |||
| 126 | So, the test whether any byte in longword1 is zero is equivalent to | ||
| 127 | testing whether tmp is nonzero. */ | ||
| 128 | |||
| 129 | while (n >= sizeof (longword)) | ||
| 130 | { | ||
| 131 | longword longword1 = *--longword_ptr ^ repeated_c; | ||
| 132 | |||
| 133 | if ((((longword1 - repeated_one) & ~longword1) | ||
| 134 | & (repeated_one << 7)) != 0) | ||
| 135 | { | ||
| 136 | longword_ptr++; | ||
| 137 | break; | ||
| 138 | } | ||
| 139 | n -= sizeof (longword); | ||
| 140 | } | ||
| 141 | |||
| 142 | char_ptr = (const unsigned char *) longword_ptr; | ||
| 143 | |||
| 144 | /* At this point, we know that either n < sizeof (longword), or one of the | ||
| 145 | sizeof (longword) bytes starting at char_ptr is == c. On little-endian | ||
| 146 | machines, we could determine the first such byte without any further | ||
| 147 | memory accesses, just by looking at the tmp result from the last loop | ||
| 148 | iteration. But this does not work on big-endian machines. Choose code | ||
| 149 | that works in both cases. */ | ||
| 150 | |||
| 151 | while (n-- > 0) | ||
| 152 | { | ||
| 153 | if (*--char_ptr == c) | ||
| 154 | return (void *) char_ptr; | ||
| 155 | } | ||
| 156 | |||
| 157 | return NULL; | ||
| 158 | } | ||
| 159 | #ifdef weak_alias | ||
| 160 | weak_alias (__memrchr, memrchr) | ||
| 161 | #endif | ||
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index e054c520ebe..c9552480e5d 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h | |||
| @@ -773,7 +773,7 @@ _GL_WARN_ON_USE (rpmatch, "rpmatch is unportable - " | |||
| 773 | _GL_FUNCDECL_SYS (secure_getenv, char *, | 773 | _GL_FUNCDECL_SYS (secure_getenv, char *, |
| 774 | (char const *name) _GL_ARG_NONNULL ((1))); | 774 | (char const *name) _GL_ARG_NONNULL ((1))); |
| 775 | # endif | 775 | # endif |
| 776 | _GL_CXXALIAS_SYS (secure_getenv, int, (char const *name)); | 776 | _GL_CXXALIAS_SYS (secure_getenv, char *, (char const *name)); |
| 777 | _GL_CXXALIASWARN (secure_getenv); | 777 | _GL_CXXALIASWARN (secure_getenv); |
| 778 | #elif defined GNULIB_POSIXCHECK | 778 | #elif defined GNULIB_POSIXCHECK |
| 779 | # undef secure_getenv | 779 | # undef secure_getenv |
diff --git a/lib/string.in.h b/lib/string.in.h new file mode 100644 index 00000000000..d7a6c9c923e --- /dev/null +++ b/lib/string.in.h | |||
| @@ -0,0 +1,1029 @@ | |||
| 1 | /* A GNU-like <string.h>. | ||
| 2 | |||
| 3 | Copyright (C) 1995-1996, 2001-2013 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This program is free software; you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation; either version 3, or (at your option) | ||
| 8 | any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ | ||
| 17 | |||
| 18 | #ifndef _@GUARD_PREFIX@_STRING_H | ||
| 19 | |||
| 20 | #if __GNUC__ >= 3 | ||
| 21 | @PRAGMA_SYSTEM_HEADER@ | ||
| 22 | #endif | ||
| 23 | @PRAGMA_COLUMNS@ | ||
| 24 | |||
| 25 | /* The include_next requires a split double-inclusion guard. */ | ||
| 26 | #@INCLUDE_NEXT@ @NEXT_STRING_H@ | ||
| 27 | |||
| 28 | #ifndef _@GUARD_PREFIX@_STRING_H | ||
| 29 | #define _@GUARD_PREFIX@_STRING_H | ||
| 30 | |||
| 31 | /* NetBSD 5.0 mis-defines NULL. */ | ||
| 32 | #include <stddef.h> | ||
| 33 | |||
| 34 | /* MirBSD defines mbslen as a macro. */ | ||
| 35 | #if @GNULIB_MBSLEN@ && defined __MirBSD__ | ||
| 36 | # include <wchar.h> | ||
| 37 | #endif | ||
| 38 | |||
| 39 | /* The __attribute__ feature is available in gcc versions 2.5 and later. | ||
| 40 | The attribute __pure__ was added in gcc 2.96. */ | ||
| 41 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) | ||
| 42 | # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) | ||
| 43 | #else | ||
| 44 | # define _GL_ATTRIBUTE_PURE /* empty */ | ||
| 45 | #endif | ||
| 46 | |||
| 47 | /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */ | ||
| 48 | /* But in any case avoid namespace pollution on glibc systems. */ | ||
| 49 | #if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \ | ||
| 50 | && ! defined __GLIBC__ | ||
| 51 | # include <unistd.h> | ||
| 52 | #endif | ||
| 53 | |||
| 54 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ | ||
| 55 | |||
| 56 | /* The definition of _GL_ARG_NONNULL is copied here. */ | ||
| 57 | |||
| 58 | /* The definition of _GL_WARN_ON_USE is copied here. */ | ||
| 59 | |||
| 60 | |||
| 61 | /* Find the index of the least-significant set bit. */ | ||
| 62 | #if @GNULIB_FFSL@ | ||
| 63 | # if !@HAVE_FFSL@ | ||
| 64 | _GL_FUNCDECL_SYS (ffsl, int, (long int i)); | ||
| 65 | # endif | ||
| 66 | _GL_CXXALIAS_SYS (ffsl, int, (long int i)); | ||
| 67 | _GL_CXXALIASWARN (ffsl); | ||
| 68 | #elif defined GNULIB_POSIXCHECK | ||
| 69 | # undef ffsl | ||
| 70 | # if HAVE_RAW_DECL_FFSL | ||
| 71 | _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module"); | ||
| 72 | # endif | ||
| 73 | #endif | ||
| 74 | |||
| 75 | |||
| 76 | /* Find the index of the least-significant set bit. */ | ||
| 77 | #if @GNULIB_FFSLL@ | ||
| 78 | # if !@HAVE_FFSLL@ | ||
| 79 | _GL_FUNCDECL_SYS (ffsll, int, (long long int i)); | ||
| 80 | # endif | ||
| 81 | _GL_CXXALIAS_SYS (ffsll, int, (long long int i)); | ||
| 82 | _GL_CXXALIASWARN (ffsll); | ||
| 83 | #elif defined GNULIB_POSIXCHECK | ||
| 84 | # undef ffsll | ||
| 85 | # if HAVE_RAW_DECL_FFSLL | ||
| 86 | _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module"); | ||
| 87 | # endif | ||
| 88 | #endif | ||
| 89 | |||
| 90 | |||
| 91 | /* Return the first instance of C within N bytes of S, or NULL. */ | ||
| 92 | #if @GNULIB_MEMCHR@ | ||
| 93 | # if @REPLACE_MEMCHR@ | ||
| 94 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 95 | # define memchr rpl_memchr | ||
| 96 | # endif | ||
| 97 | _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n) | ||
| 98 | _GL_ATTRIBUTE_PURE | ||
| 99 | _GL_ARG_NONNULL ((1))); | ||
| 100 | _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n)); | ||
| 101 | # else | ||
| 102 | # if ! @HAVE_MEMCHR@ | ||
| 103 | _GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n) | ||
| 104 | _GL_ATTRIBUTE_PURE | ||
| 105 | _GL_ARG_NONNULL ((1))); | ||
| 106 | # endif | ||
| 107 | /* On some systems, this function is defined as an overloaded function: | ||
| 108 | extern "C" { const void * std::memchr (const void *, int, size_t); } | ||
| 109 | extern "C++" { void * std::memchr (void *, int, size_t); } */ | ||
| 110 | _GL_CXXALIAS_SYS_CAST2 (memchr, | ||
| 111 | void *, (void const *__s, int __c, size_t __n), | ||
| 112 | void const *, (void const *__s, int __c, size_t __n)); | ||
| 113 | # endif | ||
| 114 | # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ | ||
| 115 | && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) | ||
| 116 | _GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n)); | ||
| 117 | _GL_CXXALIASWARN1 (memchr, void const *, | ||
| 118 | (void const *__s, int __c, size_t __n)); | ||
| 119 | # else | ||
| 120 | _GL_CXXALIASWARN (memchr); | ||
| 121 | # endif | ||
| 122 | #elif defined GNULIB_POSIXCHECK | ||
| 123 | # undef memchr | ||
| 124 | /* Assume memchr is always declared. */ | ||
| 125 | _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - " | ||
| 126 | "use gnulib module memchr for portability" ); | ||
| 127 | #endif | ||
| 128 | |||
| 129 | /* Return the first occurrence of NEEDLE in HAYSTACK. */ | ||
| 130 | #if @GNULIB_MEMMEM@ | ||
| 131 | # if @REPLACE_MEMMEM@ | ||
| 132 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 133 | # define memmem rpl_memmem | ||
| 134 | # endif | ||
| 135 | _GL_FUNCDECL_RPL (memmem, void *, | ||
| 136 | (void const *__haystack, size_t __haystack_len, | ||
| 137 | void const *__needle, size_t __needle_len) | ||
| 138 | _GL_ATTRIBUTE_PURE | ||
| 139 | _GL_ARG_NONNULL ((1, 3))); | ||
| 140 | _GL_CXXALIAS_RPL (memmem, void *, | ||
| 141 | (void const *__haystack, size_t __haystack_len, | ||
| 142 | void const *__needle, size_t __needle_len)); | ||
| 143 | # else | ||
| 144 | # if ! @HAVE_DECL_MEMMEM@ | ||
| 145 | _GL_FUNCDECL_SYS (memmem, void *, | ||
| 146 | (void const *__haystack, size_t __haystack_len, | ||
| 147 | void const *__needle, size_t __needle_len) | ||
| 148 | _GL_ATTRIBUTE_PURE | ||
| 149 | _GL_ARG_NONNULL ((1, 3))); | ||
| 150 | # endif | ||
| 151 | _GL_CXXALIAS_SYS (memmem, void *, | ||
| 152 | (void const *__haystack, size_t __haystack_len, | ||
| 153 | void const *__needle, size_t __needle_len)); | ||
| 154 | # endif | ||
| 155 | _GL_CXXALIASWARN (memmem); | ||
| 156 | #elif defined GNULIB_POSIXCHECK | ||
| 157 | # undef memmem | ||
| 158 | # if HAVE_RAW_DECL_MEMMEM | ||
| 159 | _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - " | ||
| 160 | "use gnulib module memmem-simple for portability, " | ||
| 161 | "and module memmem for speed" ); | ||
| 162 | # endif | ||
| 163 | #endif | ||
| 164 | |||
| 165 | /* Copy N bytes of SRC to DEST, return pointer to bytes after the | ||
| 166 | last written byte. */ | ||
| 167 | #if @GNULIB_MEMPCPY@ | ||
| 168 | # if ! @HAVE_MEMPCPY@ | ||
| 169 | _GL_FUNCDECL_SYS (mempcpy, void *, | ||
| 170 | (void *restrict __dest, void const *restrict __src, | ||
| 171 | size_t __n) | ||
| 172 | _GL_ARG_NONNULL ((1, 2))); | ||
| 173 | # endif | ||
| 174 | _GL_CXXALIAS_SYS (mempcpy, void *, | ||
| 175 | (void *restrict __dest, void const *restrict __src, | ||
| 176 | size_t __n)); | ||
| 177 | _GL_CXXALIASWARN (mempcpy); | ||
| 178 | #elif defined GNULIB_POSIXCHECK | ||
| 179 | # undef mempcpy | ||
| 180 | # if HAVE_RAW_DECL_MEMPCPY | ||
| 181 | _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - " | ||
| 182 | "use gnulib module mempcpy for portability"); | ||
| 183 | # endif | ||
| 184 | #endif | ||
| 185 | |||
| 186 | /* Search backwards through a block for a byte (specified as an int). */ | ||
| 187 | #if @GNULIB_MEMRCHR@ | ||
| 188 | # if ! @HAVE_DECL_MEMRCHR@ | ||
| 189 | _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t) | ||
| 190 | _GL_ATTRIBUTE_PURE | ||
| 191 | _GL_ARG_NONNULL ((1))); | ||
| 192 | # endif | ||
| 193 | /* On some systems, this function is defined as an overloaded function: | ||
| 194 | extern "C++" { const void * std::memrchr (const void *, int, size_t); } | ||
| 195 | extern "C++" { void * std::memrchr (void *, int, size_t); } */ | ||
| 196 | _GL_CXXALIAS_SYS_CAST2 (memrchr, | ||
| 197 | void *, (void const *, int, size_t), | ||
| 198 | void const *, (void const *, int, size_t)); | ||
| 199 | # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ | ||
| 200 | && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) | ||
| 201 | _GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t)); | ||
| 202 | _GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t)); | ||
| 203 | # else | ||
| 204 | _GL_CXXALIASWARN (memrchr); | ||
| 205 | # endif | ||
| 206 | #elif defined GNULIB_POSIXCHECK | ||
| 207 | # undef memrchr | ||
| 208 | # if HAVE_RAW_DECL_MEMRCHR | ||
| 209 | _GL_WARN_ON_USE (memrchr, "memrchr is unportable - " | ||
| 210 | "use gnulib module memrchr for portability"); | ||
| 211 | # endif | ||
| 212 | #endif | ||
| 213 | |||
| 214 | /* Find the first occurrence of C in S. More efficient than | ||
| 215 | memchr(S,C,N), at the expense of undefined behavior if C does not | ||
| 216 | occur within N bytes. */ | ||
| 217 | #if @GNULIB_RAWMEMCHR@ | ||
| 218 | # if ! @HAVE_RAWMEMCHR@ | ||
| 219 | _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in) | ||
| 220 | _GL_ATTRIBUTE_PURE | ||
| 221 | _GL_ARG_NONNULL ((1))); | ||
| 222 | # endif | ||
| 223 | /* On some systems, this function is defined as an overloaded function: | ||
| 224 | extern "C++" { const void * std::rawmemchr (const void *, int); } | ||
| 225 | extern "C++" { void * std::rawmemchr (void *, int); } */ | ||
| 226 | _GL_CXXALIAS_SYS_CAST2 (rawmemchr, | ||
| 227 | void *, (void const *__s, int __c_in), | ||
| 228 | void const *, (void const *__s, int __c_in)); | ||
| 229 | # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ | ||
| 230 | && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) | ||
| 231 | _GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in)); | ||
| 232 | _GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in)); | ||
| 233 | # else | ||
| 234 | _GL_CXXALIASWARN (rawmemchr); | ||
| 235 | # endif | ||
| 236 | #elif defined GNULIB_POSIXCHECK | ||
| 237 | # undef rawmemchr | ||
| 238 | # if HAVE_RAW_DECL_RAWMEMCHR | ||
| 239 | _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - " | ||
| 240 | "use gnulib module rawmemchr for portability"); | ||
| 241 | # endif | ||
| 242 | #endif | ||
| 243 | |||
| 244 | /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ | ||
| 245 | #if @GNULIB_STPCPY@ | ||
| 246 | # if ! @HAVE_STPCPY@ | ||
| 247 | _GL_FUNCDECL_SYS (stpcpy, char *, | ||
| 248 | (char *restrict __dst, char const *restrict __src) | ||
| 249 | _GL_ARG_NONNULL ((1, 2))); | ||
| 250 | # endif | ||
| 251 | _GL_CXXALIAS_SYS (stpcpy, char *, | ||
| 252 | (char *restrict __dst, char const *restrict __src)); | ||
| 253 | _GL_CXXALIASWARN (stpcpy); | ||
| 254 | #elif defined GNULIB_POSIXCHECK | ||
| 255 | # undef stpcpy | ||
| 256 | # if HAVE_RAW_DECL_STPCPY | ||
| 257 | _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - " | ||
| 258 | "use gnulib module stpcpy for portability"); | ||
| 259 | # endif | ||
| 260 | #endif | ||
| 261 | |||
| 262 | /* Copy no more than N bytes of SRC to DST, returning a pointer past the | ||
| 263 | last non-NUL byte written into DST. */ | ||
| 264 | #if @GNULIB_STPNCPY@ | ||
| 265 | # if @REPLACE_STPNCPY@ | ||
| 266 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 267 | # undef stpncpy | ||
| 268 | # define stpncpy rpl_stpncpy | ||
| 269 | # endif | ||
| 270 | _GL_FUNCDECL_RPL (stpncpy, char *, | ||
| 271 | (char *restrict __dst, char const *restrict __src, | ||
| 272 | size_t __n) | ||
| 273 | _GL_ARG_NONNULL ((1, 2))); | ||
| 274 | _GL_CXXALIAS_RPL (stpncpy, char *, | ||
| 275 | (char *restrict __dst, char const *restrict __src, | ||
| 276 | size_t __n)); | ||
| 277 | # else | ||
| 278 | # if ! @HAVE_STPNCPY@ | ||
| 279 | _GL_FUNCDECL_SYS (stpncpy, char *, | ||
| 280 | (char *restrict __dst, char const *restrict __src, | ||
| 281 | size_t __n) | ||
| 282 | _GL_ARG_NONNULL ((1, 2))); | ||
| 283 | # endif | ||
| 284 | _GL_CXXALIAS_SYS (stpncpy, char *, | ||
| 285 | (char *restrict __dst, char const *restrict __src, | ||
| 286 | size_t __n)); | ||
| 287 | # endif | ||
| 288 | _GL_CXXALIASWARN (stpncpy); | ||
| 289 | #elif defined GNULIB_POSIXCHECK | ||
| 290 | # undef stpncpy | ||
| 291 | # if HAVE_RAW_DECL_STPNCPY | ||
| 292 | _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - " | ||
| 293 | "use gnulib module stpncpy for portability"); | ||
| 294 | # endif | ||
| 295 | #endif | ||
| 296 | |||
| 297 | #if defined GNULIB_POSIXCHECK | ||
| 298 | /* strchr() does not work with multibyte strings if the locale encoding is | ||
| 299 | GB18030 and the character to be searched is a digit. */ | ||
| 300 | # undef strchr | ||
| 301 | /* Assume strchr is always declared. */ | ||
| 302 | _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings " | ||
| 303 | "in some multibyte locales - " | ||
| 304 | "use mbschr if you care about internationalization"); | ||
| 305 | #endif | ||
| 306 | |||
| 307 | /* Find the first occurrence of C in S or the final NUL byte. */ | ||
| 308 | #if @GNULIB_STRCHRNUL@ | ||
| 309 | # if @REPLACE_STRCHRNUL@ | ||
| 310 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 311 | # define strchrnul rpl_strchrnul | ||
| 312 | # endif | ||
| 313 | _GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in) | ||
| 314 | _GL_ATTRIBUTE_PURE | ||
| 315 | _GL_ARG_NONNULL ((1))); | ||
| 316 | _GL_CXXALIAS_RPL (strchrnul, char *, | ||
| 317 | (const char *str, int ch)); | ||
| 318 | # else | ||
| 319 | # if ! @HAVE_STRCHRNUL@ | ||
| 320 | _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in) | ||
| 321 | _GL_ATTRIBUTE_PURE | ||
| 322 | _GL_ARG_NONNULL ((1))); | ||
| 323 | # endif | ||
| 324 | /* On some systems, this function is defined as an overloaded function: | ||
| 325 | extern "C++" { const char * std::strchrnul (const char *, int); } | ||
| 326 | extern "C++" { char * std::strchrnul (char *, int); } */ | ||
| 327 | _GL_CXXALIAS_SYS_CAST2 (strchrnul, | ||
| 328 | char *, (char const *__s, int __c_in), | ||
| 329 | char const *, (char const *__s, int __c_in)); | ||
| 330 | # endif | ||
| 331 | # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ | ||
| 332 | && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) | ||
| 333 | _GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in)); | ||
| 334 | _GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in)); | ||
| 335 | # else | ||
| 336 | _GL_CXXALIASWARN (strchrnul); | ||
| 337 | # endif | ||
| 338 | #elif defined GNULIB_POSIXCHECK | ||
| 339 | # undef strchrnul | ||
| 340 | # if HAVE_RAW_DECL_STRCHRNUL | ||
| 341 | _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - " | ||
| 342 | "use gnulib module strchrnul for portability"); | ||
| 343 | # endif | ||
| 344 | #endif | ||
| 345 | |||
| 346 | /* Duplicate S, returning an identical malloc'd string. */ | ||
| 347 | #if @GNULIB_STRDUP@ | ||
| 348 | # if @REPLACE_STRDUP@ | ||
| 349 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 350 | # undef strdup | ||
| 351 | # define strdup rpl_strdup | ||
| 352 | # endif | ||
| 353 | _GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); | ||
| 354 | _GL_CXXALIAS_RPL (strdup, char *, (char const *__s)); | ||
| 355 | # else | ||
| 356 | # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup | ||
| 357 | /* strdup exists as a function and as a macro. Get rid of the macro. */ | ||
| 358 | # undef strdup | ||
| 359 | # endif | ||
| 360 | # if !(@HAVE_DECL_STRDUP@ || defined strdup) | ||
| 361 | _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); | ||
| 362 | # endif | ||
| 363 | _GL_CXXALIAS_SYS (strdup, char *, (char const *__s)); | ||
| 364 | # endif | ||
| 365 | _GL_CXXALIASWARN (strdup); | ||
| 366 | #elif defined GNULIB_POSIXCHECK | ||
| 367 | # undef strdup | ||
| 368 | # if HAVE_RAW_DECL_STRDUP | ||
| 369 | _GL_WARN_ON_USE (strdup, "strdup is unportable - " | ||
| 370 | "use gnulib module strdup for portability"); | ||
| 371 | # endif | ||
| 372 | #endif | ||
| 373 | |||
| 374 | /* Append no more than N characters from SRC onto DEST. */ | ||
| 375 | #if @GNULIB_STRNCAT@ | ||
| 376 | # if @REPLACE_STRNCAT@ | ||
| 377 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 378 | # undef strncat | ||
| 379 | # define strncat rpl_strncat | ||
| 380 | # endif | ||
| 381 | _GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n) | ||
| 382 | _GL_ARG_NONNULL ((1, 2))); | ||
| 383 | _GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n)); | ||
| 384 | # else | ||
| 385 | _GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n)); | ||
| 386 | # endif | ||
| 387 | _GL_CXXALIASWARN (strncat); | ||
| 388 | #elif defined GNULIB_POSIXCHECK | ||
| 389 | # undef strncat | ||
| 390 | # if HAVE_RAW_DECL_STRNCAT | ||
| 391 | _GL_WARN_ON_USE (strncat, "strncat is unportable - " | ||
| 392 | "use gnulib module strncat for portability"); | ||
| 393 | # endif | ||
| 394 | #endif | ||
| 395 | |||
| 396 | /* Return a newly allocated copy of at most N bytes of STRING. */ | ||
| 397 | #if @GNULIB_STRNDUP@ | ||
| 398 | # if @REPLACE_STRNDUP@ | ||
| 399 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 400 | # undef strndup | ||
| 401 | # define strndup rpl_strndup | ||
| 402 | # endif | ||
| 403 | _GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n) | ||
| 404 | _GL_ARG_NONNULL ((1))); | ||
| 405 | _GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n)); | ||
| 406 | # else | ||
| 407 | # if ! @HAVE_DECL_STRNDUP@ | ||
| 408 | _GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n) | ||
| 409 | _GL_ARG_NONNULL ((1))); | ||
| 410 | # endif | ||
| 411 | _GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n)); | ||
| 412 | # endif | ||
| 413 | _GL_CXXALIASWARN (strndup); | ||
| 414 | #elif defined GNULIB_POSIXCHECK | ||
| 415 | # undef strndup | ||
| 416 | # if HAVE_RAW_DECL_STRNDUP | ||
| 417 | _GL_WARN_ON_USE (strndup, "strndup is unportable - " | ||
| 418 | "use gnulib module strndup for portability"); | ||
| 419 | # endif | ||
| 420 | #endif | ||
| 421 | |||
| 422 | /* Find the length (number of bytes) of STRING, but scan at most | ||
| 423 | MAXLEN bytes. If no '\0' terminator is found in that many bytes, | ||
| 424 | return MAXLEN. */ | ||
| 425 | #if @GNULIB_STRNLEN@ | ||
| 426 | # if @REPLACE_STRNLEN@ | ||
| 427 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 428 | # undef strnlen | ||
| 429 | # define strnlen rpl_strnlen | ||
| 430 | # endif | ||
| 431 | _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen) | ||
| 432 | _GL_ATTRIBUTE_PURE | ||
| 433 | _GL_ARG_NONNULL ((1))); | ||
| 434 | _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)); | ||
| 435 | # else | ||
| 436 | # if ! @HAVE_DECL_STRNLEN@ | ||
| 437 | _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen) | ||
| 438 | _GL_ATTRIBUTE_PURE | ||
| 439 | _GL_ARG_NONNULL ((1))); | ||
| 440 | # endif | ||
| 441 | _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)); | ||
| 442 | # endif | ||
| 443 | _GL_CXXALIASWARN (strnlen); | ||
| 444 | #elif defined GNULIB_POSIXCHECK | ||
| 445 | # undef strnlen | ||
| 446 | # if HAVE_RAW_DECL_STRNLEN | ||
| 447 | _GL_WARN_ON_USE (strnlen, "strnlen is unportable - " | ||
| 448 | "use gnulib module strnlen for portability"); | ||
| 449 | # endif | ||
| 450 | #endif | ||
| 451 | |||
| 452 | #if defined GNULIB_POSIXCHECK | ||
| 453 | /* strcspn() assumes the second argument is a list of single-byte characters. | ||
| 454 | Even in this simple case, it does not work with multibyte strings if the | ||
| 455 | locale encoding is GB18030 and one of the characters to be searched is a | ||
| 456 | digit. */ | ||
| 457 | # undef strcspn | ||
| 458 | /* Assume strcspn is always declared. */ | ||
| 459 | _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings " | ||
| 460 | "in multibyte locales - " | ||
| 461 | "use mbscspn if you care about internationalization"); | ||
| 462 | #endif | ||
| 463 | |||
| 464 | /* Find the first occurrence in S of any character in ACCEPT. */ | ||
| 465 | #if @GNULIB_STRPBRK@ | ||
| 466 | # if ! @HAVE_STRPBRK@ | ||
| 467 | _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept) | ||
| 468 | _GL_ATTRIBUTE_PURE | ||
| 469 | _GL_ARG_NONNULL ((1, 2))); | ||
| 470 | # endif | ||
| 471 | /* On some systems, this function is defined as an overloaded function: | ||
| 472 | extern "C" { const char * strpbrk (const char *, const char *); } | ||
| 473 | extern "C++" { char * strpbrk (char *, const char *); } */ | ||
| 474 | _GL_CXXALIAS_SYS_CAST2 (strpbrk, | ||
| 475 | char *, (char const *__s, char const *__accept), | ||
| 476 | const char *, (char const *__s, char const *__accept)); | ||
| 477 | # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ | ||
| 478 | && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) | ||
| 479 | _GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept)); | ||
| 480 | _GL_CXXALIASWARN1 (strpbrk, char const *, | ||
| 481 | (char const *__s, char const *__accept)); | ||
| 482 | # else | ||
| 483 | _GL_CXXALIASWARN (strpbrk); | ||
| 484 | # endif | ||
| 485 | # if defined GNULIB_POSIXCHECK | ||
| 486 | /* strpbrk() assumes the second argument is a list of single-byte characters. | ||
| 487 | Even in this simple case, it does not work with multibyte strings if the | ||
| 488 | locale encoding is GB18030 and one of the characters to be searched is a | ||
| 489 | digit. */ | ||
| 490 | # undef strpbrk | ||
| 491 | _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings " | ||
| 492 | "in multibyte locales - " | ||
| 493 | "use mbspbrk if you care about internationalization"); | ||
| 494 | # endif | ||
| 495 | #elif defined GNULIB_POSIXCHECK | ||
| 496 | # undef strpbrk | ||
| 497 | # if HAVE_RAW_DECL_STRPBRK | ||
| 498 | _GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - " | ||
| 499 | "use gnulib module strpbrk for portability"); | ||
| 500 | # endif | ||
| 501 | #endif | ||
| 502 | |||
| 503 | #if defined GNULIB_POSIXCHECK | ||
| 504 | /* strspn() assumes the second argument is a list of single-byte characters. | ||
| 505 | Even in this simple case, it cannot work with multibyte strings. */ | ||
| 506 | # undef strspn | ||
| 507 | /* Assume strspn is always declared. */ | ||
| 508 | _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings " | ||
| 509 | "in multibyte locales - " | ||
| 510 | "use mbsspn if you care about internationalization"); | ||
| 511 | #endif | ||
| 512 | |||
| 513 | #if defined GNULIB_POSIXCHECK | ||
| 514 | /* strrchr() does not work with multibyte strings if the locale encoding is | ||
| 515 | GB18030 and the character to be searched is a digit. */ | ||
| 516 | # undef strrchr | ||
| 517 | /* Assume strrchr is always declared. */ | ||
| 518 | _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings " | ||
| 519 | "in some multibyte locales - " | ||
| 520 | "use mbsrchr if you care about internationalization"); | ||
| 521 | #endif | ||
| 522 | |||
| 523 | /* Search the next delimiter (char listed in DELIM) starting at *STRINGP. | ||
| 524 | If one is found, overwrite it with a NUL, and advance *STRINGP | ||
| 525 | to point to the next char after it. Otherwise, set *STRINGP to NULL. | ||
| 526 | If *STRINGP was already NULL, nothing happens. | ||
| 527 | Return the old value of *STRINGP. | ||
| 528 | |||
| 529 | This is a variant of strtok() that is multithread-safe and supports | ||
| 530 | empty fields. | ||
| 531 | |||
| 532 | Caveat: It modifies the original string. | ||
| 533 | Caveat: These functions cannot be used on constant strings. | ||
| 534 | Caveat: The identity of the delimiting character is lost. | ||
| 535 | Caveat: It doesn't work with multibyte strings unless all of the delimiter | ||
| 536 | characters are ASCII characters < 0x30. | ||
| 537 | |||
| 538 | See also strtok_r(). */ | ||
| 539 | #if @GNULIB_STRSEP@ | ||
| 540 | # if ! @HAVE_STRSEP@ | ||
| 541 | _GL_FUNCDECL_SYS (strsep, char *, | ||
| 542 | (char **restrict __stringp, char const *restrict __delim) | ||
| 543 | _GL_ARG_NONNULL ((1, 2))); | ||
| 544 | # endif | ||
| 545 | _GL_CXXALIAS_SYS (strsep, char *, | ||
| 546 | (char **restrict __stringp, char const *restrict __delim)); | ||
| 547 | _GL_CXXALIASWARN (strsep); | ||
| 548 | # if defined GNULIB_POSIXCHECK | ||
| 549 | # undef strsep | ||
| 550 | _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings " | ||
| 551 | "in multibyte locales - " | ||
| 552 | "use mbssep if you care about internationalization"); | ||
| 553 | # endif | ||
| 554 | #elif defined GNULIB_POSIXCHECK | ||
| 555 | # undef strsep | ||
| 556 | # if HAVE_RAW_DECL_STRSEP | ||
| 557 | _GL_WARN_ON_USE (strsep, "strsep is unportable - " | ||
| 558 | "use gnulib module strsep for portability"); | ||
| 559 | # endif | ||
| 560 | #endif | ||
| 561 | |||
| 562 | #if @GNULIB_STRSTR@ | ||
| 563 | # if @REPLACE_STRSTR@ | ||
| 564 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 565 | # define strstr rpl_strstr | ||
| 566 | # endif | ||
| 567 | _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle) | ||
| 568 | _GL_ATTRIBUTE_PURE | ||
| 569 | _GL_ARG_NONNULL ((1, 2))); | ||
| 570 | _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle)); | ||
| 571 | # else | ||
| 572 | /* On some systems, this function is defined as an overloaded function: | ||
| 573 | extern "C++" { const char * strstr (const char *, const char *); } | ||
| 574 | extern "C++" { char * strstr (char *, const char *); } */ | ||
| 575 | _GL_CXXALIAS_SYS_CAST2 (strstr, | ||
| 576 | char *, (const char *haystack, const char *needle), | ||
| 577 | const char *, (const char *haystack, const char *needle)); | ||
| 578 | # endif | ||
| 579 | # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ | ||
| 580 | && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) | ||
| 581 | _GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle)); | ||
| 582 | _GL_CXXALIASWARN1 (strstr, const char *, | ||
| 583 | (const char *haystack, const char *needle)); | ||
| 584 | # else | ||
| 585 | _GL_CXXALIASWARN (strstr); | ||
| 586 | # endif | ||
| 587 | #elif defined GNULIB_POSIXCHECK | ||
| 588 | /* strstr() does not work with multibyte strings if the locale encoding is | ||
| 589 | different from UTF-8: | ||
| 590 | POSIX says that it operates on "strings", and "string" in POSIX is defined | ||
| 591 | as a sequence of bytes, not of characters. */ | ||
| 592 | # undef strstr | ||
| 593 | /* Assume strstr is always declared. */ | ||
| 594 | _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot " | ||
| 595 | "work correctly on character strings in most " | ||
| 596 | "multibyte locales - " | ||
| 597 | "use mbsstr if you care about internationalization, " | ||
| 598 | "or use strstr if you care about speed"); | ||
| 599 | #endif | ||
| 600 | |||
| 601 | /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive | ||
| 602 | comparison. */ | ||
| 603 | #if @GNULIB_STRCASESTR@ | ||
| 604 | # if @REPLACE_STRCASESTR@ | ||
| 605 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 606 | # define strcasestr rpl_strcasestr | ||
| 607 | # endif | ||
| 608 | _GL_FUNCDECL_RPL (strcasestr, char *, | ||
| 609 | (const char *haystack, const char *needle) | ||
| 610 | _GL_ATTRIBUTE_PURE | ||
| 611 | _GL_ARG_NONNULL ((1, 2))); | ||
| 612 | _GL_CXXALIAS_RPL (strcasestr, char *, | ||
| 613 | (const char *haystack, const char *needle)); | ||
| 614 | # else | ||
| 615 | # if ! @HAVE_STRCASESTR@ | ||
| 616 | _GL_FUNCDECL_SYS (strcasestr, char *, | ||
| 617 | (const char *haystack, const char *needle) | ||
| 618 | _GL_ATTRIBUTE_PURE | ||
| 619 | _GL_ARG_NONNULL ((1, 2))); | ||
| 620 | # endif | ||
| 621 | /* On some systems, this function is defined as an overloaded function: | ||
| 622 | extern "C++" { const char * strcasestr (const char *, const char *); } | ||
| 623 | extern "C++" { char * strcasestr (char *, const char *); } */ | ||
| 624 | _GL_CXXALIAS_SYS_CAST2 (strcasestr, | ||
| 625 | char *, (const char *haystack, const char *needle), | ||
| 626 | const char *, (const char *haystack, const char *needle)); | ||
| 627 | # endif | ||
| 628 | # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ | ||
| 629 | && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) | ||
| 630 | _GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle)); | ||
| 631 | _GL_CXXALIASWARN1 (strcasestr, const char *, | ||
| 632 | (const char *haystack, const char *needle)); | ||
| 633 | # else | ||
| 634 | _GL_CXXALIASWARN (strcasestr); | ||
| 635 | # endif | ||
| 636 | #elif defined GNULIB_POSIXCHECK | ||
| 637 | /* strcasestr() does not work with multibyte strings: | ||
| 638 | It is a glibc extension, and glibc implements it only for unibyte | ||
| 639 | locales. */ | ||
| 640 | # undef strcasestr | ||
| 641 | # if HAVE_RAW_DECL_STRCASESTR | ||
| 642 | _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character " | ||
| 643 | "strings in multibyte locales - " | ||
| 644 | "use mbscasestr if you care about " | ||
| 645 | "internationalization, or use c-strcasestr if you want " | ||
| 646 | "a locale independent function"); | ||
| 647 | # endif | ||
| 648 | #endif | ||
| 649 | |||
| 650 | /* Parse S into tokens separated by characters in DELIM. | ||
| 651 | If S is NULL, the saved pointer in SAVE_PTR is used as | ||
| 652 | the next starting point. For example: | ||
| 653 | char s[] = "-abc-=-def"; | ||
| 654 | char *sp; | ||
| 655 | x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" | ||
| 656 | x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL | ||
| 657 | x = strtok_r(NULL, "=", &sp); // x = NULL | ||
| 658 | // s = "abc\0-def\0" | ||
| 659 | |||
| 660 | This is a variant of strtok() that is multithread-safe. | ||
| 661 | |||
| 662 | For the POSIX documentation for this function, see: | ||
| 663 | http://www.opengroup.org/susv3xsh/strtok.html | ||
| 664 | |||
| 665 | Caveat: It modifies the original string. | ||
| 666 | Caveat: These functions cannot be used on constant strings. | ||
| 667 | Caveat: The identity of the delimiting character is lost. | ||
| 668 | Caveat: It doesn't work with multibyte strings unless all of the delimiter | ||
| 669 | characters are ASCII characters < 0x30. | ||
| 670 | |||
| 671 | See also strsep(). */ | ||
| 672 | #if @GNULIB_STRTOK_R@ | ||
| 673 | # if @REPLACE_STRTOK_R@ | ||
| 674 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 675 | # undef strtok_r | ||
| 676 | # define strtok_r rpl_strtok_r | ||
| 677 | # endif | ||
| 678 | _GL_FUNCDECL_RPL (strtok_r, char *, | ||
| 679 | (char *restrict s, char const *restrict delim, | ||
| 680 | char **restrict save_ptr) | ||
| 681 | _GL_ARG_NONNULL ((2, 3))); | ||
| 682 | _GL_CXXALIAS_RPL (strtok_r, char *, | ||
| 683 | (char *restrict s, char const *restrict delim, | ||
| 684 | char **restrict save_ptr)); | ||
| 685 | # else | ||
| 686 | # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK | ||
| 687 | # undef strtok_r | ||
| 688 | # endif | ||
| 689 | # if ! @HAVE_DECL_STRTOK_R@ | ||
| 690 | _GL_FUNCDECL_SYS (strtok_r, char *, | ||
| 691 | (char *restrict s, char const *restrict delim, | ||
| 692 | char **restrict save_ptr) | ||
| 693 | _GL_ARG_NONNULL ((2, 3))); | ||
| 694 | # endif | ||
| 695 | _GL_CXXALIAS_SYS (strtok_r, char *, | ||
| 696 | (char *restrict s, char const *restrict delim, | ||
| 697 | char **restrict save_ptr)); | ||
| 698 | # endif | ||
| 699 | _GL_CXXALIASWARN (strtok_r); | ||
| 700 | # if defined GNULIB_POSIXCHECK | ||
| 701 | _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character " | ||
| 702 | "strings in multibyte locales - " | ||
| 703 | "use mbstok_r if you care about internationalization"); | ||
| 704 | # endif | ||
| 705 | #elif defined GNULIB_POSIXCHECK | ||
| 706 | # undef strtok_r | ||
| 707 | # if HAVE_RAW_DECL_STRTOK_R | ||
| 708 | _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - " | ||
| 709 | "use gnulib module strtok_r for portability"); | ||
| 710 | # endif | ||
| 711 | #endif | ||
| 712 | |||
| 713 | |||
| 714 | /* The following functions are not specified by POSIX. They are gnulib | ||
| 715 | extensions. */ | ||
| 716 | |||
| 717 | #if @GNULIB_MBSLEN@ | ||
| 718 | /* Return the number of multibyte characters in the character string STRING. | ||
| 719 | This considers multibyte characters, unlike strlen, which counts bytes. */ | ||
| 720 | # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */ | ||
| 721 | # undef mbslen | ||
| 722 | # endif | ||
| 723 | # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */ | ||
| 724 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 725 | # define mbslen rpl_mbslen | ||
| 726 | # endif | ||
| 727 | _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) | ||
| 728 | _GL_ATTRIBUTE_PURE | ||
| 729 | _GL_ARG_NONNULL ((1))); | ||
| 730 | _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string)); | ||
| 731 | # else | ||
| 732 | _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) | ||
| 733 | _GL_ATTRIBUTE_PURE | ||
| 734 | _GL_ARG_NONNULL ((1))); | ||
| 735 | _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string)); | ||
| 736 | # endif | ||
| 737 | _GL_CXXALIASWARN (mbslen); | ||
| 738 | #endif | ||
| 739 | |||
| 740 | #if @GNULIB_MBSNLEN@ | ||
| 741 | /* Return the number of multibyte characters in the character string starting | ||
| 742 | at STRING and ending at STRING + LEN. */ | ||
| 743 | _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len) | ||
| 744 | _GL_ATTRIBUTE_PURE | ||
| 745 | _GL_ARG_NONNULL ((1)); | ||
| 746 | #endif | ||
| 747 | |||
| 748 | #if @GNULIB_MBSCHR@ | ||
| 749 | /* Locate the first single-byte character C in the character string STRING, | ||
| 750 | and return a pointer to it. Return NULL if C is not found in STRING. | ||
| 751 | Unlike strchr(), this function works correctly in multibyte locales with | ||
| 752 | encodings such as GB18030. */ | ||
| 753 | # if defined __hpux | ||
| 754 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 755 | # define mbschr rpl_mbschr /* avoid collision with HP-UX function */ | ||
| 756 | # endif | ||
| 757 | _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c) | ||
| 758 | _GL_ATTRIBUTE_PURE | ||
| 759 | _GL_ARG_NONNULL ((1))); | ||
| 760 | _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c)); | ||
| 761 | # else | ||
| 762 | _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c) | ||
| 763 | _GL_ATTRIBUTE_PURE | ||
| 764 | _GL_ARG_NONNULL ((1))); | ||
| 765 | _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c)); | ||
| 766 | # endif | ||
| 767 | _GL_CXXALIASWARN (mbschr); | ||
| 768 | #endif | ||
| 769 | |||
| 770 | #if @GNULIB_MBSRCHR@ | ||
| 771 | /* Locate the last single-byte character C in the character string STRING, | ||
| 772 | and return a pointer to it. Return NULL if C is not found in STRING. | ||
| 773 | Unlike strrchr(), this function works correctly in multibyte locales with | ||
| 774 | encodings such as GB18030. */ | ||
| 775 | # if defined __hpux || defined __INTERIX | ||
| 776 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 777 | # define mbsrchr rpl_mbsrchr /* avoid collision with system function */ | ||
| 778 | # endif | ||
| 779 | _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c) | ||
| 780 | _GL_ATTRIBUTE_PURE | ||
| 781 | _GL_ARG_NONNULL ((1))); | ||
| 782 | _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c)); | ||
| 783 | # else | ||
| 784 | _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c) | ||
| 785 | _GL_ATTRIBUTE_PURE | ||
| 786 | _GL_ARG_NONNULL ((1))); | ||
| 787 | _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c)); | ||
| 788 | # endif | ||
| 789 | _GL_CXXALIASWARN (mbsrchr); | ||
| 790 | #endif | ||
| 791 | |||
| 792 | #if @GNULIB_MBSSTR@ | ||
| 793 | /* Find the first occurrence of the character string NEEDLE in the character | ||
| 794 | string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. | ||
| 795 | Unlike strstr(), this function works correctly in multibyte locales with | ||
| 796 | encodings different from UTF-8. */ | ||
| 797 | _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle) | ||
| 798 | _GL_ATTRIBUTE_PURE | ||
| 799 | _GL_ARG_NONNULL ((1, 2)); | ||
| 800 | #endif | ||
| 801 | |||
| 802 | #if @GNULIB_MBSCASECMP@ | ||
| 803 | /* Compare the character strings S1 and S2, ignoring case, returning less than, | ||
| 804 | equal to or greater than zero if S1 is lexicographically less than, equal to | ||
| 805 | or greater than S2. | ||
| 806 | Note: This function may, in multibyte locales, return 0 for strings of | ||
| 807 | different lengths! | ||
| 808 | Unlike strcasecmp(), this function works correctly in multibyte locales. */ | ||
| 809 | _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2) | ||
| 810 | _GL_ATTRIBUTE_PURE | ||
| 811 | _GL_ARG_NONNULL ((1, 2)); | ||
| 812 | #endif | ||
| 813 | |||
| 814 | #if @GNULIB_MBSNCASECMP@ | ||
| 815 | /* Compare the initial segment of the character string S1 consisting of at most | ||
| 816 | N characters with the initial segment of the character string S2 consisting | ||
| 817 | of at most N characters, ignoring case, returning less than, equal to or | ||
| 818 | greater than zero if the initial segment of S1 is lexicographically less | ||
| 819 | than, equal to or greater than the initial segment of S2. | ||
| 820 | Note: This function may, in multibyte locales, return 0 for initial segments | ||
| 821 | of different lengths! | ||
| 822 | Unlike strncasecmp(), this function works correctly in multibyte locales. | ||
| 823 | But beware that N is not a byte count but a character count! */ | ||
| 824 | _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n) | ||
| 825 | _GL_ATTRIBUTE_PURE | ||
| 826 | _GL_ARG_NONNULL ((1, 2)); | ||
| 827 | #endif | ||
| 828 | |||
| 829 | #if @GNULIB_MBSPCASECMP@ | ||
| 830 | /* Compare the initial segment of the character string STRING consisting of | ||
| 831 | at most mbslen (PREFIX) characters with the character string PREFIX, | ||
| 832 | ignoring case. If the two match, return a pointer to the first byte | ||
| 833 | after this prefix in STRING. Otherwise, return NULL. | ||
| 834 | Note: This function may, in multibyte locales, return non-NULL if STRING | ||
| 835 | is of smaller length than PREFIX! | ||
| 836 | Unlike strncasecmp(), this function works correctly in multibyte | ||
| 837 | locales. */ | ||
| 838 | _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix) | ||
| 839 | _GL_ATTRIBUTE_PURE | ||
| 840 | _GL_ARG_NONNULL ((1, 2)); | ||
| 841 | #endif | ||
| 842 | |||
| 843 | #if @GNULIB_MBSCASESTR@ | ||
| 844 | /* Find the first occurrence of the character string NEEDLE in the character | ||
| 845 | string HAYSTACK, using case-insensitive comparison. | ||
| 846 | Note: This function may, in multibyte locales, return success even if | ||
| 847 | strlen (haystack) < strlen (needle) ! | ||
| 848 | Unlike strcasestr(), this function works correctly in multibyte locales. */ | ||
| 849 | _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle) | ||
| 850 | _GL_ATTRIBUTE_PURE | ||
| 851 | _GL_ARG_NONNULL ((1, 2)); | ||
| 852 | #endif | ||
| 853 | |||
| 854 | #if @GNULIB_MBSCSPN@ | ||
| 855 | /* Find the first occurrence in the character string STRING of any character | ||
| 856 | in the character string ACCEPT. Return the number of bytes from the | ||
| 857 | beginning of the string to this occurrence, or to the end of the string | ||
| 858 | if none exists. | ||
| 859 | Unlike strcspn(), this function works correctly in multibyte locales. */ | ||
| 860 | _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept) | ||
| 861 | _GL_ATTRIBUTE_PURE | ||
| 862 | _GL_ARG_NONNULL ((1, 2)); | ||
| 863 | #endif | ||
| 864 | |||
| 865 | #if @GNULIB_MBSPBRK@ | ||
| 866 | /* Find the first occurrence in the character string STRING of any character | ||
| 867 | in the character string ACCEPT. Return the pointer to it, or NULL if none | ||
| 868 | exists. | ||
| 869 | Unlike strpbrk(), this function works correctly in multibyte locales. */ | ||
| 870 | # if defined __hpux | ||
| 871 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 872 | # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ | ||
| 873 | # endif | ||
| 874 | _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept) | ||
| 875 | _GL_ATTRIBUTE_PURE | ||
| 876 | _GL_ARG_NONNULL ((1, 2))); | ||
| 877 | _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept)); | ||
| 878 | # else | ||
| 879 | _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept) | ||
| 880 | _GL_ATTRIBUTE_PURE | ||
| 881 | _GL_ARG_NONNULL ((1, 2))); | ||
| 882 | _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept)); | ||
| 883 | # endif | ||
| 884 | _GL_CXXALIASWARN (mbspbrk); | ||
| 885 | #endif | ||
| 886 | |||
| 887 | #if @GNULIB_MBSSPN@ | ||
| 888 | /* Find the first occurrence in the character string STRING of any character | ||
| 889 | not in the character string REJECT. Return the number of bytes from the | ||
| 890 | beginning of the string to this occurrence, or to the end of the string | ||
| 891 | if none exists. | ||
| 892 | Unlike strspn(), this function works correctly in multibyte locales. */ | ||
| 893 | _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject) | ||
| 894 | _GL_ATTRIBUTE_PURE | ||
| 895 | _GL_ARG_NONNULL ((1, 2)); | ||
| 896 | #endif | ||
| 897 | |||
| 898 | #if @GNULIB_MBSSEP@ | ||
| 899 | /* Search the next delimiter (multibyte character listed in the character | ||
| 900 | string DELIM) starting at the character string *STRINGP. | ||
| 901 | If one is found, overwrite it with a NUL, and advance *STRINGP to point | ||
| 902 | to the next multibyte character after it. Otherwise, set *STRINGP to NULL. | ||
| 903 | If *STRINGP was already NULL, nothing happens. | ||
| 904 | Return the old value of *STRINGP. | ||
| 905 | |||
| 906 | This is a variant of mbstok_r() that supports empty fields. | ||
| 907 | |||
| 908 | Caveat: It modifies the original string. | ||
| 909 | Caveat: These functions cannot be used on constant strings. | ||
| 910 | Caveat: The identity of the delimiting character is lost. | ||
| 911 | |||
| 912 | See also mbstok_r(). */ | ||
| 913 | _GL_EXTERN_C char * mbssep (char **stringp, const char *delim) | ||
| 914 | _GL_ARG_NONNULL ((1, 2)); | ||
| 915 | #endif | ||
| 916 | |||
| 917 | #if @GNULIB_MBSTOK_R@ | ||
| 918 | /* Parse the character string STRING into tokens separated by characters in | ||
| 919 | the character string DELIM. | ||
| 920 | If STRING is NULL, the saved pointer in SAVE_PTR is used as | ||
| 921 | the next starting point. For example: | ||
| 922 | char s[] = "-abc-=-def"; | ||
| 923 | char *sp; | ||
| 924 | x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" | ||
| 925 | x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL | ||
| 926 | x = mbstok_r(NULL, "=", &sp); // x = NULL | ||
| 927 | // s = "abc\0-def\0" | ||
| 928 | |||
| 929 | Caveat: It modifies the original string. | ||
| 930 | Caveat: These functions cannot be used on constant strings. | ||
| 931 | Caveat: The identity of the delimiting character is lost. | ||
| 932 | |||
| 933 | See also mbssep(). */ | ||
| 934 | _GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr) | ||
| 935 | _GL_ARG_NONNULL ((2, 3)); | ||
| 936 | #endif | ||
| 937 | |||
| 938 | /* Map any int, typically from errno, into an error message. */ | ||
| 939 | #if @GNULIB_STRERROR@ | ||
| 940 | # if @REPLACE_STRERROR@ | ||
| 941 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 942 | # undef strerror | ||
| 943 | # define strerror rpl_strerror | ||
| 944 | # endif | ||
| 945 | _GL_FUNCDECL_RPL (strerror, char *, (int)); | ||
| 946 | _GL_CXXALIAS_RPL (strerror, char *, (int)); | ||
| 947 | # else | ||
| 948 | _GL_CXXALIAS_SYS (strerror, char *, (int)); | ||
| 949 | # endif | ||
| 950 | _GL_CXXALIASWARN (strerror); | ||
| 951 | #elif defined GNULIB_POSIXCHECK | ||
| 952 | # undef strerror | ||
| 953 | /* Assume strerror is always declared. */ | ||
| 954 | _GL_WARN_ON_USE (strerror, "strerror is unportable - " | ||
| 955 | "use gnulib module strerror to guarantee non-NULL result"); | ||
| 956 | #endif | ||
| 957 | |||
| 958 | /* Map any int, typically from errno, into an error message. Multithread-safe. | ||
| 959 | Uses the POSIX declaration, not the glibc declaration. */ | ||
| 960 | #if @GNULIB_STRERROR_R@ | ||
| 961 | # if @REPLACE_STRERROR_R@ | ||
| 962 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 963 | # undef strerror_r | ||
| 964 | # define strerror_r rpl_strerror_r | ||
| 965 | # endif | ||
| 966 | _GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen) | ||
| 967 | _GL_ARG_NONNULL ((2))); | ||
| 968 | _GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)); | ||
| 969 | # else | ||
| 970 | # if !@HAVE_DECL_STRERROR_R@ | ||
| 971 | _GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen) | ||
| 972 | _GL_ARG_NONNULL ((2))); | ||
| 973 | # endif | ||
| 974 | _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)); | ||
| 975 | # endif | ||
| 976 | # if @HAVE_DECL_STRERROR_R@ | ||
| 977 | _GL_CXXALIASWARN (strerror_r); | ||
| 978 | # endif | ||
| 979 | #elif defined GNULIB_POSIXCHECK | ||
| 980 | # undef strerror_r | ||
| 981 | # if HAVE_RAW_DECL_STRERROR_R | ||
| 982 | _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - " | ||
| 983 | "use gnulib module strerror_r-posix for portability"); | ||
| 984 | # endif | ||
| 985 | #endif | ||
| 986 | |||
| 987 | #if @GNULIB_STRSIGNAL@ | ||
| 988 | # if @REPLACE_STRSIGNAL@ | ||
| 989 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 990 | # define strsignal rpl_strsignal | ||
| 991 | # endif | ||
| 992 | _GL_FUNCDECL_RPL (strsignal, char *, (int __sig)); | ||
| 993 | _GL_CXXALIAS_RPL (strsignal, char *, (int __sig)); | ||
| 994 | # else | ||
| 995 | # if ! @HAVE_DECL_STRSIGNAL@ | ||
| 996 | _GL_FUNCDECL_SYS (strsignal, char *, (int __sig)); | ||
| 997 | # endif | ||
| 998 | /* Need to cast, because on Cygwin 1.5.x systems, the return type is | ||
| 999 | 'const char *'. */ | ||
| 1000 | _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig)); | ||
| 1001 | # endif | ||
| 1002 | _GL_CXXALIASWARN (strsignal); | ||
| 1003 | #elif defined GNULIB_POSIXCHECK | ||
| 1004 | # undef strsignal | ||
| 1005 | # if HAVE_RAW_DECL_STRSIGNAL | ||
| 1006 | _GL_WARN_ON_USE (strsignal, "strsignal is unportable - " | ||
| 1007 | "use gnulib module strsignal for portability"); | ||
| 1008 | # endif | ||
| 1009 | #endif | ||
| 1010 | |||
| 1011 | #if @GNULIB_STRVERSCMP@ | ||
| 1012 | # if !@HAVE_STRVERSCMP@ | ||
| 1013 | _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *) | ||
| 1014 | _GL_ATTRIBUTE_PURE | ||
| 1015 | _GL_ARG_NONNULL ((1, 2))); | ||
| 1016 | # endif | ||
| 1017 | _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *)); | ||
| 1018 | _GL_CXXALIASWARN (strverscmp); | ||
| 1019 | #elif defined GNULIB_POSIXCHECK | ||
| 1020 | # undef strverscmp | ||
| 1021 | # if HAVE_RAW_DECL_STRVERSCMP | ||
| 1022 | _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - " | ||
| 1023 | "use gnulib module strverscmp for portability"); | ||
| 1024 | # endif | ||
| 1025 | #endif | ||
| 1026 | |||
| 1027 | |||
| 1028 | #endif /* _@GUARD_PREFIX@_STRING_H */ | ||
| 1029 | #endif /* _@GUARD_PREFIX@_STRING_H */ | ||
diff --git a/lib/unsetenv.c b/lib/unsetenv.c index eea21129031..c58c82f4f44 100644 --- a/lib/unsetenv.c +++ b/lib/unsetenv.c | |||
| @@ -14,12 +14,12 @@ | |||
| 14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 16 | 16 | ||
| 17 | #include <config.h> | ||
| 18 | |||
| 19 | /* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc | 17 | /* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc |
| 20 | optimizes away the name == NULL test below. */ | 18 | optimizes away the name == NULL test below. */ |
| 21 | #define _GL_ARG_NONNULL(params) | 19 | #define _GL_ARG_NONNULL(params) |
| 22 | 20 | ||
| 21 | #include <config.h> | ||
| 22 | |||
| 23 | /* Specification. */ | 23 | /* Specification. */ |
| 24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
| 25 | 25 | ||