string2.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. /* Machine-independant string function optimizations.
  2. Copyright (C) 1997,1998,1999,2000,2001,2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  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. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #ifndef _STRING_H
  18. # error "Never use <bits/string2.h> directly; include <string.h> instead."
  19. #endif
  20. #if !defined __NO_STRING_INLINES && !defined __BOUNDED_POINTERS__
  21. /* Unlike the definitions in the header <bits/string.h> the
  22. definitions contained here are not optimized down to assembler
  23. level. Those optimizations are not always a good idea since this
  24. means the code size increases a lot. Instead the definitions here
  25. optimize some functions in a way which do not dramatically
  26. increase the code size and which do not use assembler. The main
  27. trick is to use GNU CC's `__builtin_constant_p' function.
  28. Every function XXX which has a defined version in
  29. <bits/string.h> must be accompanied by a symbol _HAVE_STRING_ARCH_XXX
  30. to make sure we don't get redefinitions.
  31. We must use here macros instead of inline functions since the
  32. trick won't work with the latter. */
  33. #ifndef __STRING_INLINE
  34. # ifdef __cplusplus
  35. # define __STRING_INLINE inline
  36. # else
  37. # define __STRING_INLINE extern __inline
  38. # endif
  39. #endif
  40. #if _STRING_ARCH_unaligned
  41. /* If we can do unaligned memory accesses we must know the endianess. */
  42. # include <endian.h>
  43. # include <bits/types.h>
  44. # if __BYTE_ORDER == __LITTLE_ENDIAN
  45. # define __STRING2_SMALL_GET16(src, idx) \
  46. (((__const unsigned char *) (__const char *) (src))[idx + 1] << 8 \
  47. | ((__const unsigned char *) (__const char *) (src))[idx])
  48. # define __STRING2_SMALL_GET32(src, idx) \
  49. (((((__const unsigned char *) (__const char *) (src))[idx + 3] << 8 \
  50. | ((__const unsigned char *) (__const char *) (src))[idx + 2]) << 8 \
  51. | ((__const unsigned char *) (__const char *) (src))[idx + 1]) << 8 \
  52. | ((__const unsigned char *) (__const char *) (src))[idx])
  53. # else
  54. # define __STRING2_SMALL_GET16(src, idx) \
  55. (((__const unsigned char *) (__const char *) (src))[idx] << 8 \
  56. | ((__const unsigned char *) (__const char *) (src))[idx + 1])
  57. # define __STRING2_SMALL_GET32(src, idx) \
  58. (((((__const unsigned char *) (__const char *) (src))[idx] << 8 \
  59. | ((__const unsigned char *) (__const char *) (src))[idx + 1]) << 8 \
  60. | ((__const unsigned char *) (__const char *) (src))[idx + 2]) << 8 \
  61. | ((__const unsigned char *) (__const char *) (src))[idx + 3])
  62. # endif
  63. #else
  64. /* These are a few types we need for the optimizations if we cannot
  65. use unaligned memory accesses. */
  66. # define __STRING2_COPY_TYPE(N) \
  67. typedef struct { unsigned char __arr[N]; } \
  68. __STRING2_COPY_ARR##N __attribute__ ((packed))
  69. __STRING2_COPY_TYPE (2);
  70. __STRING2_COPY_TYPE (3);
  71. __STRING2_COPY_TYPE (4);
  72. __STRING2_COPY_TYPE (5);
  73. __STRING2_COPY_TYPE (6);
  74. __STRING2_COPY_TYPE (7);
  75. __STRING2_COPY_TYPE (8);
  76. # undef __STRING2_COPY_TYPE
  77. #endif
  78. /* Dereferencing a pointer arg to run sizeof on it fails for the void
  79. pointer case, so we use this instead.
  80. Note that __x is evaluated twice. */
  81. #define __string2_1bptr_p(__x) \
  82. ((size_t)(const void *)((__x) + 1) - (size_t)(const void *)(__x) == 1)
  83. /* Set N bytes of S to C. */
  84. #ifndef _HAVE_STRING_ARCH_memset
  85. # if _STRING_ARCH_unaligned
  86. # define memset(s, c, n) \
  87. (__extension__ (__builtin_constant_p (n) && (n) <= 16 \
  88. ? ((n) == 1 \
  89. ? __memset_1 (s, c) \
  90. : __memset_gc (s, c, n)) \
  91. : (__builtin_constant_p (c) && (c) == '\0' \
  92. ? ({ void *__s = (s); __bzero (__s, n); __s; }) \
  93. : memset (s, c, n))))
  94. # define __memset_1(s, c) ({ void *__s = (s); \
  95. *((__uint8_t *) __s) = (__uint8_t) c; __s; })
  96. # define __memset_gc(s, c, n) \
  97. ({ void *__s = (s); \
  98. union { \
  99. unsigned int __ui; \
  100. unsigned short int __usi; \
  101. unsigned char __uc; \
  102. } *__u = __s; \
  103. __uint8_t __c = (__uint8_t) (c); \
  104. \
  105. /* This `switch' statement will be removed at compile-time. */ \
  106. switch ((unsigned int) (n)) \
  107. { \
  108. case 15: \
  109. __u->__ui = __c * 0x01010101; \
  110. __u = __extension__ (void *)((char *) __u + 4); \
  111. case 11: \
  112. __u->__ui = __c * 0x01010101; \
  113. __u = __extension__ (void *)((char *) __u + 4); \
  114. case 7: \
  115. __u->__ui = __c * 0x01010101; \
  116. __u = __extension__ (void *)((char *) __u + 4); \
  117. case 3: \
  118. __u->__usi = (unsigned short int) __c * 0x0101; \
  119. __u = __extension__ (void *)((char *) __u + 2); \
  120. __u->__uc = (unsigned char) __c; \
  121. break; \
  122. \
  123. case 14: \
  124. __u->__ui = __c * 0x01010101; \
  125. __u = __extension__ (void *)((char *) __u + 4); \
  126. case 10: \
  127. __u->__ui = __c * 0x01010101; \
  128. __u = __extension__ (void *)((char *) __u + 4); \
  129. case 6: \
  130. __u->__ui = __c * 0x01010101; \
  131. __u = __extension__ (void *)((char *) __u + 4); \
  132. case 2: \
  133. __u->__usi = (unsigned short int) __c * 0x0101; \
  134. break; \
  135. \
  136. case 13: \
  137. __u->__ui = __c * 0x01010101; \
  138. __u = __extension__ (void *)((char *) __u + 4); \
  139. case 9: \
  140. __u->__ui = __c * 0x01010101; \
  141. __u = __extension__ (void *)((char *) __u + 4); \
  142. case 5: \
  143. __u->__ui = __c * 0x01010101; \
  144. __u = __extension__ (void *)((char *) __u + 4); \
  145. case 1: \
  146. __u->__uc = (unsigned char) __c; \
  147. break; \
  148. \
  149. case 16: \
  150. __u->__ui = __c * 0x01010101; \
  151. __u = __extension__ (void *)((char *) __u + 4); \
  152. case 12: \
  153. __u->__ui = __c * 0x01010101; \
  154. __u = __extension__ (void *)((char *) __u + 4); \
  155. case 8: \
  156. __u->__ui = __c * 0x01010101; \
  157. __u = __extension__ (void *)((char *) __u + 4); \
  158. case 4: \
  159. __u->__ui = __c * 0x01010101; \
  160. case 0: \
  161. break; \
  162. } \
  163. \
  164. __s; })
  165. # else
  166. # define memset(s, c, n) \
  167. (__extension__ (__builtin_constant_p (c) && (c) == '\0' \
  168. ? ({ void *__s = (s); __bzero (__s, n); __s; }) \
  169. : memset (s, c, n)))
  170. # endif
  171. /* GCC optimizes memset(s, 0, n) but not bzero(s, n).
  172. The optimization is broken before EGCS 1.1. */
  173. # if __GNUC_PREREQ (2, 91)
  174. # define __bzero(s, n) __builtin_memset (s, '\0', n)
  175. # endif
  176. #endif
  177. /* Copy N bytes from SRC to DEST, returning pointer to byte following the
  178. last copied. */
  179. #ifdef __USE_GNU
  180. # if !defined _HAVE_STRING_ARCH_mempcpy || defined _FORCE_INLINES
  181. # ifndef _HAVE_STRING_ARCH_mempcpy
  182. # if __GNUC_PREREQ (3, 0)
  183. # define __mempcpy(dest, src, n) \
  184. (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
  185. && __string2_1bptr_p (src) && n <= 8 \
  186. ? __builtin_memcpy (dest, src, n) + (n) \
  187. : __mempcpy (dest, src, n)))
  188. # else
  189. # define __mempcpy(dest, src, n) \
  190. (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
  191. && __string2_1bptr_p (src) && n <= 8 \
  192. ? __mempcpy_small (dest, __mempcpy_args (src), n) \
  193. : __mempcpy (dest, src, n)))
  194. # endif
  195. /* In glibc we use this function frequently but for namespace reasons
  196. we have to use the name `__mempcpy'. */
  197. # define mempcpy(dest, src, n) __mempcpy (dest, src, n)
  198. # endif
  199. # if !__GNUC_PREREQ (3, 0) || defined _FORCE_INLINES
  200. # if _STRING_ARCH_unaligned
  201. # ifndef _FORCE_INLINES
  202. # define __mempcpy_args(src) \
  203. ((__const char *) (src))[0], ((__const char *) (src))[2], \
  204. ((__const char *) (src))[4], ((__const char *) (src))[6], \
  205. __extension__ __STRING2_SMALL_GET16 (src, 0), \
  206. __extension__ __STRING2_SMALL_GET16 (src, 4), \
  207. __extension__ __STRING2_SMALL_GET32 (src, 0), \
  208. __extension__ __STRING2_SMALL_GET32 (src, 4)
  209. # endif
  210. __STRING_INLINE void *__mempcpy_small (void *, char, char, char, char,
  211. __uint16_t, __uint16_t, __uint32_t,
  212. __uint32_t, size_t);
  213. __STRING_INLINE void *
  214. __mempcpy_small (void *__dest1,
  215. char __src0_1, char __src2_1, char __src4_1, char __src6_1,
  216. __uint16_t __src0_2, __uint16_t __src4_2,
  217. __uint32_t __src0_4, __uint32_t __src4_4,
  218. size_t __srclen)
  219. {
  220. union {
  221. __uint32_t __ui;
  222. __uint16_t __usi;
  223. unsigned char __uc;
  224. unsigned char __c;
  225. } *__u = __dest1;
  226. switch ((unsigned int) __srclen)
  227. {
  228. case 1:
  229. __u->__c = __src0_1;
  230. __u = __extension__ (void *)((char *) __u + 1);
  231. break;
  232. case 2:
  233. __u->__usi = __src0_2;
  234. __u = __extension__ (void *)((char *) __u + 2);
  235. break;
  236. case 3:
  237. __u->__usi = __src0_2;
  238. __u = __extension__ (void *)((char *) __u + 2);
  239. __u->__c = __src2_1;
  240. __u = __extension__ (void *)((char *) __u + 1);
  241. break;
  242. case 4:
  243. __u->__ui = __src0_4;
  244. __u = __extension__ (void *)((char *) __u + 4);
  245. break;
  246. case 5:
  247. __u->__ui = __src0_4;
  248. __u = __extension__ (void *)((char *) __u + 4);
  249. __u->__c = __src4_1;
  250. __u = __extension__ (void *)((char *) __u + 1);
  251. break;
  252. case 6:
  253. __u->__ui = __src0_4;
  254. __u = __extension__ (void *)((char *) __u + 4);
  255. __u->__usi = __src4_2;
  256. __u = __extension__ (void *)((char *) __u + 2);
  257. break;
  258. case 7:
  259. __u->__ui = __src0_4;
  260. __u = __extension__ (void *)((char *) __u + 4);
  261. __u->__usi = __src4_2;
  262. __u = __extension__ (void *)((char *) __u + 2);
  263. __u->__c = __src6_1;
  264. __u = __extension__ (void *)((char *) __u + 1);
  265. break;
  266. case 8:
  267. __u->__ui = __src0_4;
  268. __u = __extension__ (void *)((char *) __u + 4);
  269. __u->__ui = __src4_4;
  270. __u = __extension__ (void *)((char *) __u + 4);
  271. break;
  272. }
  273. return (void *) __u;
  274. }
  275. # else
  276. # ifndef _FORCE_INLINES
  277. # define __mempcpy_args(src) \
  278. ((__const char *) (src))[0], \
  279. __extension__ ((__STRING2_COPY_ARR2) \
  280. { { ((__const char *) (src))[0], ((__const char *) (src))[1] } }), \
  281. __extension__ ((__STRING2_COPY_ARR3) \
  282. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  283. ((__const char *) (src))[2] } }), \
  284. __extension__ ((__STRING2_COPY_ARR4) \
  285. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  286. ((__const char *) (src))[2], ((__const char *) (src))[3] } }), \
  287. __extension__ ((__STRING2_COPY_ARR5) \
  288. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  289. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  290. ((__const char *) (src))[4] } }), \
  291. __extension__ ((__STRING2_COPY_ARR6) \
  292. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  293. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  294. ((__const char *) (src))[4], ((__const char *) (src))[5] } }), \
  295. __extension__ ((__STRING2_COPY_ARR7) \
  296. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  297. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  298. ((__const char *) (src))[4], ((__const char *) (src))[5], \
  299. ((__const char *) (src))[6] } }), \
  300. __extension__ ((__STRING2_COPY_ARR8) \
  301. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  302. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  303. ((__const char *) (src))[4], ((__const char *) (src))[5], \
  304. ((__const char *) (src))[6], ((__const char *) (src))[7] } })
  305. # endif
  306. __STRING_INLINE void *__mempcpy_small (void *, char, __STRING2_COPY_ARR2,
  307. __STRING2_COPY_ARR3,
  308. __STRING2_COPY_ARR4,
  309. __STRING2_COPY_ARR5,
  310. __STRING2_COPY_ARR6,
  311. __STRING2_COPY_ARR7,
  312. __STRING2_COPY_ARR8, size_t);
  313. __STRING_INLINE void *
  314. __mempcpy_small (void *__dest, char __src1,
  315. __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3,
  316. __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5,
  317. __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7,
  318. __STRING2_COPY_ARR8 __src8, size_t __srclen)
  319. {
  320. union {
  321. char __c;
  322. __STRING2_COPY_ARR2 __sca2;
  323. __STRING2_COPY_ARR3 __sca3;
  324. __STRING2_COPY_ARR4 __sca4;
  325. __STRING2_COPY_ARR5 __sca5;
  326. __STRING2_COPY_ARR6 __sca6;
  327. __STRING2_COPY_ARR7 __sca7;
  328. __STRING2_COPY_ARR8 __sca8;
  329. } *__u = __dest;
  330. switch ((unsigned int) __srclen)
  331. {
  332. case 1:
  333. __u->__c = __src1;
  334. break;
  335. case 2:
  336. __extension__ __u->__sca2 = __src2;
  337. break;
  338. case 3:
  339. __extension__ __u->__sca3 = __src3;
  340. break;
  341. case 4:
  342. __extension__ __u->__sca4 = __src4;
  343. break;
  344. case 5:
  345. __extension__ __u->__sca5 = __src5;
  346. break;
  347. case 6:
  348. __extension__ __u->__sca6 = __src6;
  349. break;
  350. case 7:
  351. __extension__ __u->__sca7 = __src7;
  352. break;
  353. case 8:
  354. __extension__ __u->__sca8 = __src8;
  355. break;
  356. }
  357. return __extension__ (void *)((char *) __u + __srclen);
  358. }
  359. # endif
  360. # endif
  361. # endif
  362. #endif
  363. /* Return pointer to C in S. */
  364. #ifndef _HAVE_STRING_ARCH_strchr
  365. extern void *__rawmemchr (const void *__s, int __c);
  366. # define strchr(s, c) \
  367. (__extension__ (__builtin_constant_p (c) && (c) == '\0' \
  368. ? (char *) __rawmemchr (s, c) \
  369. : strchr (s, c)))
  370. #endif
  371. /* Copy SRC to DEST. */
  372. #if (!defined _HAVE_STRING_ARCH_strcpy && !__GNUC_PREREQ (3, 0)) \
  373. || defined _FORCE_INLINES
  374. # if !defined _HAVE_STRING_ARCH_strcpy && !__GNUC_PREREQ (3, 0)
  375. # define strcpy(dest, src) \
  376. (__extension__ (__builtin_constant_p (src) \
  377. ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \
  378. ? __strcpy_small (dest, __strcpy_args (src), \
  379. strlen (src) + 1) \
  380. : (char *) memcpy (dest, src, strlen (src) + 1)) \
  381. : strcpy (dest, src)))
  382. # endif
  383. # if _STRING_ARCH_unaligned
  384. # ifndef _FORCE_INLINES
  385. # define __strcpy_args(src) \
  386. __extension__ __STRING2_SMALL_GET16 (src, 0), \
  387. __extension__ __STRING2_SMALL_GET16 (src, 4), \
  388. __extension__ __STRING2_SMALL_GET32 (src, 0), \
  389. __extension__ __STRING2_SMALL_GET32 (src, 4)
  390. # endif
  391. __STRING_INLINE char *__strcpy_small (char *, __uint16_t, __uint16_t,
  392. __uint32_t, __uint32_t, size_t);
  393. __STRING_INLINE char *
  394. __strcpy_small (char *__dest,
  395. __uint16_t __src0_2, __uint16_t __src4_2,
  396. __uint32_t __src0_4, __uint32_t __src4_4,
  397. size_t __srclen)
  398. {
  399. union {
  400. __uint32_t __ui;
  401. __uint16_t __usi;
  402. unsigned char __uc;
  403. } *__u = (void *) __dest;
  404. switch ((unsigned int) __srclen)
  405. {
  406. case 1:
  407. __u->__uc = '\0';
  408. break;
  409. case 2:
  410. __u->__usi = __src0_2;
  411. break;
  412. case 3:
  413. __u->__usi = __src0_2;
  414. __u = __extension__ (void *)((char *) __u + 2);
  415. __u->__uc = '\0';
  416. break;
  417. case 4:
  418. __u->__ui = __src0_4;
  419. break;
  420. case 5:
  421. __u->__ui = __src0_4;
  422. __u = __extension__ (void *)((char *) __u + 4);
  423. __u->__uc = '\0';
  424. break;
  425. case 6:
  426. __u->__ui = __src0_4;
  427. __u = __extension__ (void *)((char *) __u + 4);
  428. __u->__usi = __src4_2;
  429. break;
  430. case 7:
  431. __u->__ui = __src0_4;
  432. __u = __extension__ (void *)((char *) __u + 4);
  433. __u->__usi = __src4_2;
  434. __u = __extension__ (void *)((char *) __u + 2);
  435. __u->__uc = '\0';
  436. break;
  437. case 8:
  438. __u->__ui = __src0_4;
  439. __u = __extension__ (void *)((char *) __u + 4);
  440. __u->__ui = __src4_4;
  441. break;
  442. }
  443. return __dest;
  444. }
  445. # else
  446. # ifndef _FORCE_INLINES
  447. # define __strcpy_args(src) \
  448. __extension__ ((__STRING2_COPY_ARR2) \
  449. { { ((__const char *) (src))[0], '\0' } }), \
  450. __extension__ ((__STRING2_COPY_ARR3) \
  451. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  452. '\0' } }), \
  453. __extension__ ((__STRING2_COPY_ARR4) \
  454. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  455. ((__const char *) (src))[2], '\0' } }), \
  456. __extension__ ((__STRING2_COPY_ARR5) \
  457. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  458. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  459. '\0' } }), \
  460. __extension__ ((__STRING2_COPY_ARR6) \
  461. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  462. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  463. ((__const char *) (src))[4], '\0' } }), \
  464. __extension__ ((__STRING2_COPY_ARR7) \
  465. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  466. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  467. ((__const char *) (src))[4], ((__const char *) (src))[5], \
  468. '\0' } }), \
  469. __extension__ ((__STRING2_COPY_ARR8) \
  470. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  471. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  472. ((__const char *) (src))[4], ((__const char *) (src))[5], \
  473. ((__const char *) (src))[6], '\0' } })
  474. # endif
  475. __STRING_INLINE char *__strcpy_small (char *, __STRING2_COPY_ARR2,
  476. __STRING2_COPY_ARR3,
  477. __STRING2_COPY_ARR4,
  478. __STRING2_COPY_ARR5,
  479. __STRING2_COPY_ARR6,
  480. __STRING2_COPY_ARR7,
  481. __STRING2_COPY_ARR8, size_t);
  482. __STRING_INLINE char *
  483. __strcpy_small (char *__dest,
  484. __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3,
  485. __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5,
  486. __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7,
  487. __STRING2_COPY_ARR8 __src8, size_t __srclen)
  488. {
  489. union {
  490. char __c;
  491. __STRING2_COPY_ARR2 __sca2;
  492. __STRING2_COPY_ARR3 __sca3;
  493. __STRING2_COPY_ARR4 __sca4;
  494. __STRING2_COPY_ARR5 __sca5;
  495. __STRING2_COPY_ARR6 __sca6;
  496. __STRING2_COPY_ARR7 __sca7;
  497. __STRING2_COPY_ARR8 __sca8;
  498. } *__u = (void *) __dest;
  499. switch ((unsigned int) __srclen)
  500. {
  501. case 1:
  502. __u->__c = '\0';
  503. break;
  504. case 2:
  505. __extension__ __u->__sca2 = __src2;
  506. break;
  507. case 3:
  508. __extension__ __u->__sca3 = __src3;
  509. break;
  510. case 4:
  511. __extension__ __u->__sca4 = __src4;
  512. break;
  513. case 5:
  514. __extension__ __u->__sca5 = __src5;
  515. break;
  516. case 6:
  517. __extension__ __u->__sca6 = __src6;
  518. break;
  519. case 7:
  520. __extension__ __u->__sca7 = __src7;
  521. break;
  522. case 8:
  523. __extension__ __u->__sca8 = __src8;
  524. break;
  525. }
  526. return __dest;
  527. }
  528. # endif
  529. #endif
  530. /* Copy SRC to DEST, returning pointer to final NUL byte. */
  531. #ifdef __USE_GNU
  532. # if !defined _HAVE_STRING_ARCH_stpcpy || defined _FORCE_INLINES
  533. # ifndef _HAVE_STRING_ARCH_stpcpy
  534. # if __GNUC_PREREQ (3, 0)
  535. # define __stpcpy(dest, src) \
  536. (__extension__ (__builtin_constant_p (src) \
  537. ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \
  538. ? __builtin_strcpy (dest, src) + strlen (src) \
  539. : ((char *) (__mempcpy) (dest, src, strlen (src) + 1) \
  540. - 1)) \
  541. : __stpcpy (dest, src)))
  542. # else
  543. # define __stpcpy(dest, src) \
  544. (__extension__ (__builtin_constant_p (src) \
  545. ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \
  546. ? __stpcpy_small (dest, __stpcpy_args (src), \
  547. strlen (src) + 1) \
  548. : ((char *) (__mempcpy) (dest, src, strlen (src) + 1) \
  549. - 1)) \
  550. : __stpcpy (dest, src)))
  551. # endif
  552. /* In glibc we use this function frequently but for namespace reasons
  553. we have to use the name `__stpcpy'. */
  554. # define stpcpy(dest, src) __stpcpy (dest, src)
  555. # endif
  556. # if !__GNUC_PREREQ (3, 0) || defined _FORCE_INLINES
  557. # if _STRING_ARCH_unaligned
  558. # ifndef _FORCE_INLINES
  559. # define __stpcpy_args(src) \
  560. __extension__ __STRING2_SMALL_GET16 (src, 0), \
  561. __extension__ __STRING2_SMALL_GET16 (src, 4), \
  562. __extension__ __STRING2_SMALL_GET32 (src, 0), \
  563. __extension__ __STRING2_SMALL_GET32 (src, 4)
  564. # endif
  565. __STRING_INLINE char *__stpcpy_small (char *, __uint16_t, __uint16_t,
  566. __uint32_t, __uint32_t, size_t);
  567. __STRING_INLINE char *
  568. __stpcpy_small (char *__dest,
  569. __uint16_t __src0_2, __uint16_t __src4_2,
  570. __uint32_t __src0_4, __uint32_t __src4_4,
  571. size_t __srclen)
  572. {
  573. union {
  574. unsigned int __ui;
  575. unsigned short int __usi;
  576. unsigned char __uc;
  577. char __c;
  578. } *__u = (void *) __dest;
  579. switch ((unsigned int) __srclen)
  580. {
  581. case 1:
  582. __u->__uc = '\0';
  583. break;
  584. case 2:
  585. __u->__usi = __src0_2;
  586. __u = __extension__ (void *)((char *) __u + 1);
  587. break;
  588. case 3:
  589. __u->__usi = __src0_2;
  590. __u = __extension__ (void *)((char *) __u + 2);
  591. __u->__uc = '\0';
  592. break;
  593. case 4:
  594. __u->__ui = __src0_4;
  595. __u = __extension__ (void *)((char *) __u + 3);
  596. break;
  597. case 5:
  598. __u->__ui = __src0_4;
  599. __u = __extension__ (void *)((char *) __u + 4);
  600. __u->__uc = '\0';
  601. break;
  602. case 6:
  603. __u->__ui = __src0_4;
  604. __u = __extension__ (void *)((char *) __u + 4);
  605. __u->__usi = __src4_2;
  606. __u = __extension__ (void *)((char *) __u + 1);
  607. break;
  608. case 7:
  609. __u->__ui = __src0_4;
  610. __u = __extension__ (void *)((char *) __u + 4);
  611. __u->__usi = __src4_2;
  612. __u = __extension__ (void *)((char *) __u + 2);
  613. __u->__uc = '\0';
  614. break;
  615. case 8:
  616. __u->__ui = __src0_4;
  617. __u = __extension__ (void *)((char *) __u + 4);
  618. __u->__ui = __src4_4;
  619. __u = __extension__ (void *)((char *) __u + 3);
  620. break;
  621. }
  622. return &__u->__c;
  623. }
  624. # else
  625. # ifndef _FORCE_INLINES
  626. # define __stpcpy_args(src) \
  627. __extension__ ((__STRING2_COPY_ARR2) \
  628. { { ((__const char *) (src))[0], '\0' } }), \
  629. __extension__ ((__STRING2_COPY_ARR3) \
  630. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  631. '\0' } }), \
  632. __extension__ ((__STRING2_COPY_ARR4) \
  633. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  634. ((__const char *) (src))[2], '\0' } }), \
  635. __extension__ ((__STRING2_COPY_ARR5) \
  636. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  637. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  638. '\0' } }), \
  639. __extension__ ((__STRING2_COPY_ARR6) \
  640. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  641. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  642. ((__const char *) (src))[4], '\0' } }), \
  643. __extension__ ((__STRING2_COPY_ARR7) \
  644. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  645. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  646. ((__const char *) (src))[4], ((__const char *) (src))[5], \
  647. '\0' } }), \
  648. __extension__ ((__STRING2_COPY_ARR8) \
  649. { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
  650. ((__const char *) (src))[2], ((__const char *) (src))[3], \
  651. ((__const char *) (src))[4], ((__const char *) (src))[5], \
  652. ((__const char *) (src))[6], '\0' } })
  653. # endif
  654. __STRING_INLINE char *__stpcpy_small (char *, __STRING2_COPY_ARR2,
  655. __STRING2_COPY_ARR3,
  656. __STRING2_COPY_ARR4,
  657. __STRING2_COPY_ARR5,
  658. __STRING2_COPY_ARR6,
  659. __STRING2_COPY_ARR7,
  660. __STRING2_COPY_ARR8, size_t);
  661. __STRING_INLINE char *
  662. __stpcpy_small (char *__dest,
  663. __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3,
  664. __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5,
  665. __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7,
  666. __STRING2_COPY_ARR8 __src8, size_t __srclen)
  667. {
  668. union {
  669. char __c;
  670. __STRING2_COPY_ARR2 __sca2;
  671. __STRING2_COPY_ARR3 __sca3;
  672. __STRING2_COPY_ARR4 __sca4;
  673. __STRING2_COPY_ARR5 __sca5;
  674. __STRING2_COPY_ARR6 __sca6;
  675. __STRING2_COPY_ARR7 __sca7;
  676. __STRING2_COPY_ARR8 __sca8;
  677. } *__u = (void *) __dest;
  678. switch ((unsigned int) __srclen)
  679. {
  680. case 1:
  681. __u->__c = '\0';
  682. break;
  683. case 2:
  684. __extension__ __u->__sca2 = __src2;
  685. break;
  686. case 3:
  687. __extension__ __u->__sca3 = __src3;
  688. break;
  689. case 4:
  690. __extension__ __u->__sca4 = __src4;
  691. break;
  692. case 5:
  693. __extension__ __u->__sca5 = __src5;
  694. break;
  695. case 6:
  696. __extension__ __u->__sca6 = __src6;
  697. break;
  698. case 7:
  699. __extension__ __u->__sca7 = __src7;
  700. break;
  701. case 8:
  702. __extension__ __u->__sca8 = __src8;
  703. break;
  704. }
  705. return __dest + __srclen - 1;
  706. }
  707. # endif
  708. # endif
  709. # endif
  710. #endif
  711. /* Copy no more than N characters of SRC to DEST. */
  712. #ifndef _HAVE_STRING_ARCH_strncpy
  713. # if defined _USE_STRING_ARCH_memset && defined _USE_STRING_ARCH_mempcpy
  714. # define strncpy(dest, src, n) \
  715. (__extension__ ({ char *__dest = (dest); \
  716. __builtin_constant_p (src) && __builtin_constant_p (n) \
  717. ? (strlen (src) + 1 >= ((size_t) (n)) \
  718. ? (char *) memcpy (__dest, src, n) \
  719. : (memset (__mempcpy (__dest, src, strlen (src)), \
  720. '\0', n - strlen (src)), \
  721. __dest)) \
  722. : strncpy (__dest, src, n); }))
  723. # else
  724. # define strncpy(dest, src, n) \
  725. (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
  726. ? (strlen (src) + 1 >= ((size_t) (n)) \
  727. ? (char *) memcpy (dest, src, n) \
  728. : strncpy (dest, src, n)) \
  729. : strncpy (dest, src, n)))
  730. # endif
  731. #endif
  732. /* Append no more than N characters from SRC onto DEST. */
  733. #ifndef _HAVE_STRING_ARCH_strncat
  734. # ifdef _USE_STRING_ARCH_strchr
  735. # define strncat(dest, src, n) \
  736. (__extension__ ({ char *__dest = (dest); \
  737. __builtin_constant_p (src) && __builtin_constant_p (n) \
  738. ? (strlen (src) < ((size_t) (n)) \
  739. ? strcat (__dest, src) \
  740. : (*((char *) __mempcpy (strchr (__dest, '\0'), \
  741. src, n)) = '\0', __dest)) \
  742. : strncat (dest, src, n); }))
  743. # else
  744. # define strncat(dest, src, n) \
  745. (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
  746. ? (strlen (src) < ((size_t) (n)) \
  747. ? strcat (dest, src) \
  748. : strncat (dest, src, n)) \
  749. : strncat (dest, src, n)))
  750. # endif
  751. #endif
  752. /* Compare characters of S1 and S2. */
  753. #ifndef _HAVE_STRING_ARCH_strcmp
  754. # define strcmp(s1, s2) \
  755. __extension__ \
  756. ({ size_t __s1_len, __s2_len; \
  757. (__builtin_constant_p (s1) && __builtin_constant_p (s2) \
  758. && (__s1_len = strlen (s1), __s2_len = strlen (s2), \
  759. (!__string2_1bptr_p (s1) || __s1_len >= 4) \
  760. && (!__string2_1bptr_p (s2) || __s2_len >= 4)) \
  761. ? memcmp ((__const char *) (s1), (__const char *) (s2), \
  762. (__s1_len < __s2_len ? __s1_len : __s2_len) + 1) \
  763. : (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
  764. && (__s1_len = strlen (s1), __s1_len < 4) \
  765. ? (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
  766. ? __strcmp_cc (s1, s2, __s1_len) \
  767. : __strcmp_cg (s1, s2, __s1_len)) \
  768. : (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
  769. && (__s2_len = strlen (s2), __s2_len < 4) \
  770. ? (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
  771. ? __strcmp_cc (s1, s2, __s2_len) \
  772. : __strcmp_gc (s1, s2, __s2_len)) \
  773. : strcmp (s1, s2)))); })
  774. # define __strcmp_cc(s1, s2, l) \
  775. (__extension__ ({ register int __result = \
  776. (((__const unsigned char *) (__const char *) (s1))[0] \
  777. - ((__const unsigned char *) (__const char *)(s2))[0]);\
  778. if (l > 0 && __result == 0) \
  779. { \
  780. __result = (((__const unsigned char *) \
  781. (__const char *) (s1))[1] \
  782. - ((__const unsigned char *) \
  783. (__const char *) (s2))[1]); \
  784. if (l > 1 && __result == 0) \
  785. { \
  786. __result = \
  787. (((__const unsigned char *) \
  788. (__const char *) (s1))[2] \
  789. - ((__const unsigned char *) \
  790. (__const char *) (s2))[2]); \
  791. if (l > 2 && __result == 0) \
  792. __result = \
  793. (((__const unsigned char *) \
  794. (__const char *) (s1))[3] \
  795. - ((__const unsigned char *) \
  796. (__const char *) (s2))[3]); \
  797. } \
  798. } \
  799. __result; }))
  800. # define __strcmp_cg(s1, s2, l1) \
  801. (__extension__ ({ __const unsigned char *__s2 = \
  802. (__const unsigned char *) (__const char *) (s2); \
  803. register int __result = \
  804. (((__const unsigned char *) (__const char *) (s1))[0] \
  805. - __s2[0]); \
  806. if (l1 > 0 && __result == 0) \
  807. { \
  808. __result = (((__const unsigned char *) \
  809. (__const char *) (s1))[1] - __s2[1]); \
  810. if (l1 > 1 && __result == 0) \
  811. { \
  812. __result = (((__const unsigned char *) \
  813. (__const char *) (s1))[2] - __s2[2]);\
  814. if (l1 > 2 && __result == 0) \
  815. __result = (((__const unsigned char *) \
  816. (__const char *) (s1))[3] \
  817. - __s2[3]); \
  818. } \
  819. } \
  820. __result; }))
  821. # define __strcmp_gc(s1, s2, l2) \
  822. (__extension__ ({ __const unsigned char *__s1 = \
  823. (__const unsigned char *) (__const char *) (s1); \
  824. register int __result = \
  825. __s1[0] - ((__const unsigned char *) \
  826. (__const char *) (s2))[0]; \
  827. if (l2 > 0 && __result == 0) \
  828. { \
  829. __result = (__s1[1] \
  830. - ((__const unsigned char *) \
  831. (__const char *) (s2))[1]); \
  832. if (l2 > 1 && __result == 0) \
  833. { \
  834. __result = \
  835. (__s1[2] - ((__const unsigned char *) \
  836. (__const char *) (s2))[2]); \
  837. if (l2 > 2 && __result == 0) \
  838. __result = \
  839. (__s1[3] \
  840. - ((__const unsigned char *) \
  841. (__const char *) (s2))[3]); \
  842. } \
  843. } \
  844. __result; }))
  845. #endif
  846. /* Compare N characters of S1 and S2. */
  847. #ifndef _HAVE_STRING_ARCH_strncmp
  848. # define strncmp(s1, s2, n) \
  849. (__extension__ (__builtin_constant_p (n) \
  850. && ((__builtin_constant_p (s1) \
  851. && strlen (s1) < ((size_t) (n))) \
  852. || (__builtin_constant_p (s2) \
  853. && strlen (s2) < ((size_t) (n)))) \
  854. ? strcmp (s1, s2) : strncmp (s1, s2, n)))
  855. #endif
  856. /* Return the length of the initial segment of S which
  857. consists entirely of characters not in REJECT. */
  858. #if !defined _HAVE_STRING_ARCH_strcspn || defined _FORCE_INLINES
  859. # ifndef _HAVE_STRING_ARCH_strcspn
  860. # define strcspn(s, reject) \
  861. __extension__ \
  862. ({ char __r0, __r1, __r2; \
  863. (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \
  864. ? ((__r0 = ((__const char *) (reject))[0], __r0 == '\0') \
  865. ? strlen (s) \
  866. : ((__r1 = ((__const char *) (reject))[1], __r1 == '\0') \
  867. ? __strcspn_c1 (s, __r0) \
  868. : ((__r2 = ((__const char *) (reject))[2], __r2 == '\0') \
  869. ? __strcspn_c2 (s, __r0, __r1) \
  870. : (((__const char *) (reject))[3] == '\0' \
  871. ? __strcspn_c3 (s, __r0, __r1, __r2) \
  872. : strcspn (s, reject))))) \
  873. : strcspn (s, reject)); })
  874. # endif
  875. __STRING_INLINE size_t __strcspn_c1 (__const char *__s, int __reject);
  876. __STRING_INLINE size_t
  877. __strcspn_c1 (__const char *__s, int __reject)
  878. {
  879. register size_t __result = 0;
  880. while (__s[__result] != '\0' && __s[__result] != __reject)
  881. ++__result;
  882. return __result;
  883. }
  884. __STRING_INLINE size_t __strcspn_c2 (__const char *__s, int __reject1,
  885. int __reject2);
  886. __STRING_INLINE size_t
  887. __strcspn_c2 (__const char *__s, int __reject1, int __reject2)
  888. {
  889. register size_t __result = 0;
  890. while (__s[__result] != '\0' && __s[__result] != __reject1
  891. && __s[__result] != __reject2)
  892. ++__result;
  893. return __result;
  894. }
  895. __STRING_INLINE size_t __strcspn_c3 (__const char *__s, int __reject1,
  896. int __reject2, int __reject3);
  897. __STRING_INLINE size_t
  898. __strcspn_c3 (__const char *__s, int __reject1, int __reject2,
  899. int __reject3)
  900. {
  901. register size_t __result = 0;
  902. while (__s[__result] != '\0' && __s[__result] != __reject1
  903. && __s[__result] != __reject2 && __s[__result] != __reject3)
  904. ++__result;
  905. return __result;
  906. }
  907. #endif
  908. /* Return the length of the initial segment of S which
  909. consists entirely of characters in ACCEPT. */
  910. #if !defined _HAVE_STRING_ARCH_strspn || defined _FORCE_INLINES
  911. # ifndef _HAVE_STRING_ARCH_strspn
  912. # define strspn(s, accept) \
  913. __extension__ \
  914. ({ char __a0, __a1, __a2; \
  915. (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
  916. ? ((__a0 = ((__const char *) (accept))[0], __a0 == '\0') \
  917. ? ((void) (s), 0) \
  918. : ((__a1 = ((__const char *) (accept))[1], __a1 == '\0') \
  919. ? __strspn_c1 (s, __a0) \
  920. : ((__a2 = ((__const char *) (accept))[2], __a2 == '\0') \
  921. ? __strspn_c2 (s, __a0, __a1) \
  922. : (((__const char *) (accept))[3] == '\0' \
  923. ? __strspn_c3 (s, __a0, __a1, __a2) \
  924. : strspn (s, accept))))) \
  925. : strspn (s, accept)); })
  926. # endif
  927. __STRING_INLINE size_t __strspn_c1 (__const char *__s, int __accept);
  928. __STRING_INLINE size_t
  929. __strspn_c1 (__const char *__s, int __accept)
  930. {
  931. register size_t __result = 0;
  932. /* Please note that __accept never can be '\0'. */
  933. while (__s[__result] == __accept)
  934. ++__result;
  935. return __result;
  936. }
  937. __STRING_INLINE size_t __strspn_c2 (__const char *__s, int __accept1,
  938. int __accept2);
  939. __STRING_INLINE size_t
  940. __strspn_c2 (__const char *__s, int __accept1, int __accept2)
  941. {
  942. register size_t __result = 0;
  943. /* Please note that __accept1 and __accept2 never can be '\0'. */
  944. while (__s[__result] == __accept1 || __s[__result] == __accept2)
  945. ++__result;
  946. return __result;
  947. }
  948. __STRING_INLINE size_t __strspn_c3 (__const char *__s, int __accept1,
  949. int __accept2, int __accept3);
  950. __STRING_INLINE size_t
  951. __strspn_c3 (__const char *__s, int __accept1, int __accept2, int __accept3)
  952. {
  953. register size_t __result = 0;
  954. /* Please note that __accept1 to __accept3 never can be '\0'. */
  955. while (__s[__result] == __accept1 || __s[__result] == __accept2
  956. || __s[__result] == __accept3)
  957. ++__result;
  958. return __result;
  959. }
  960. #endif
  961. /* Find the first occurrence in S of any character in ACCEPT. */
  962. #if !defined _HAVE_STRING_ARCH_strpbrk || defined _FORCE_INLINES
  963. # ifndef _HAVE_STRING_ARCH_strpbrk
  964. # define strpbrk(s, accept) \
  965. __extension__ \
  966. ({ char __a0, __a1, __a2; \
  967. (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
  968. ? ((__a0 = ((__const char *) (accept))[0], __a0 == '\0') \
  969. ? ((void) (s), NULL) \
  970. : ((__a1 = ((__const char *) (accept))[1], __a1 == '\0') \
  971. ? strchr (s, __a0) \
  972. : ((__a2 = ((__const char *) (accept))[2], __a2 == '\0') \
  973. ? __strpbrk_c2 (s, __a0, __a1) \
  974. : (((__const char *) (accept))[3] == '\0' \
  975. ? __strpbrk_c3 (s, __a0, __a1, __a2) \
  976. : strpbrk (s, accept))))) \
  977. : strpbrk (s, accept)); })
  978. # endif
  979. __STRING_INLINE char *__strpbrk_c2 (__const char *__s, int __accept1,
  980. int __accept2);
  981. __STRING_INLINE char *
  982. __strpbrk_c2 (__const char *__s, int __accept1, int __accept2)
  983. {
  984. /* Please note that __accept1 and __accept2 never can be '\0'. */
  985. while (*__s != '\0' && *__s != __accept1 && *__s != __accept2)
  986. ++__s;
  987. return *__s == '\0' ? NULL : (char *) (size_t) __s;
  988. }
  989. __STRING_INLINE char *__strpbrk_c3 (__const char *__s, int __accept1,
  990. int __accept2, int __accept3);
  991. __STRING_INLINE char *
  992. __strpbrk_c3 (__const char *__s, int __accept1, int __accept2,
  993. int __accept3)
  994. {
  995. /* Please note that __accept1 to __accept3 never can be '\0'. */
  996. while (*__s != '\0' && *__s != __accept1 && *__s != __accept2
  997. && *__s != __accept3)
  998. ++__s;
  999. return *__s == '\0' ? NULL : (char *) (size_t) __s;
  1000. }
  1001. #endif
  1002. /* Find the first occurrence of NEEDLE in HAYSTACK. Newer gcc versions
  1003. do this itself. */
  1004. #if !defined _HAVE_STRING_ARCH_strstr && !__GNUC_PREREQ (2, 97)
  1005. # define strstr(haystack, needle) \
  1006. (__extension__ (__builtin_constant_p (needle) && __string2_1bptr_p (needle) \
  1007. ? (((__const char *) (needle))[0] == '\0' \
  1008. ? (char *) (size_t) (haystack) \
  1009. : (((__const char *) (needle))[1] == '\0' \
  1010. ? strchr (haystack, \
  1011. ((__const char *) (needle))[0]) \
  1012. : strstr (haystack, needle))) \
  1013. : strstr (haystack, needle)))
  1014. #endif
  1015. #if !defined _HAVE_STRING_ARCH_strtok_r || defined _FORCE_INLINES
  1016. # ifndef _HAVE_STRING_ARCH_strtok_r
  1017. # define __strtok_r(s, sep, nextp) \
  1018. (__extension__ (__builtin_constant_p (sep) && __string2_1bptr_p (sep) \
  1019. ? (((__const char *) (sep))[0] != '\0' \
  1020. && ((__const char *) (sep))[1] == '\0' \
  1021. ? __strtok_r_1c (s, ((__const char *) (sep))[0], nextp) \
  1022. : __strtok_r (s, sep, nextp)) \
  1023. : __strtok_r (s, sep, nextp)))
  1024. # endif
  1025. __STRING_INLINE char *__strtok_r_1c (char *__s, char __sep, char **__nextp);
  1026. __STRING_INLINE char *
  1027. __strtok_r_1c (char *__s, char __sep, char **__nextp)
  1028. {
  1029. char *__result;
  1030. if (__s == NULL)
  1031. __s = *__nextp;
  1032. while (*__s == __sep)
  1033. ++__s;
  1034. __result = NULL;
  1035. if (*__s != '\0')
  1036. {
  1037. __result = __s++;
  1038. while (*__s != '\0')
  1039. if (*__s++ == __sep)
  1040. {
  1041. __s[-1] = '\0';
  1042. break;
  1043. }
  1044. *__nextp = __s;
  1045. }
  1046. return __result;
  1047. }
  1048. # if defined __USE_POSIX || defined __USE_MISC
  1049. # define strtok_r(s, sep, nextp) __strtok_r (s, sep, nextp)
  1050. # endif
  1051. #endif
  1052. #if !defined _HAVE_STRING_ARCH_strsep || defined _FORCE_INLINES
  1053. # ifndef _HAVE_STRING_ARCH_strsep
  1054. extern char *__strsep_g (char **__stringp, __const char *__delim);
  1055. # define __strsep(s, reject) \
  1056. __extension__ \
  1057. ({ char __r0, __r1, __r2; \
  1058. (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \
  1059. && (__r0 = ((__const char *) (reject))[0], \
  1060. ((__const char *) (reject))[0] != '\0') \
  1061. ? ((__r1 = ((__const char *) (reject))[1], \
  1062. ((__const char *) (reject))[1] == '\0') \
  1063. ? __strsep_1c (s, __r0) \
  1064. : ((__r2 = ((__const char *) (reject))[2], __r2 == '\0') \
  1065. ? __strsep_2c (s, __r0, __r1) \
  1066. : (((__const char *) (reject))[3] == '\0' \
  1067. ? __strsep_3c (s, __r0, __r1, __r2) \
  1068. : __strsep_g (s, reject)))) \
  1069. : __strsep_g (s, reject)); })
  1070. # endif
  1071. __STRING_INLINE char *__strsep_1c (char **__s, char __reject);
  1072. __STRING_INLINE char *
  1073. __strsep_1c (char **__s, char __reject)
  1074. {
  1075. register char *__retval = *__s;
  1076. if (__retval != NULL && (*__s = strchr (__retval, __reject)) != NULL)
  1077. *(*__s)++ = '\0';
  1078. return __retval;
  1079. }
  1080. __STRING_INLINE char *__strsep_2c (char **__s, char __reject1, char __reject2);
  1081. __STRING_INLINE char *
  1082. __strsep_2c (char **__s, char __reject1, char __reject2)
  1083. {
  1084. register char *__retval = *__s;
  1085. if (__retval != NULL)
  1086. {
  1087. register char *__cp = __retval;
  1088. while (1)
  1089. {
  1090. if (*__cp == '\0')
  1091. {
  1092. __cp = NULL;
  1093. break;
  1094. }
  1095. if (*__cp == __reject1 || *__cp == __reject2)
  1096. {
  1097. *__cp++ = '\0';
  1098. break;
  1099. }
  1100. ++__cp;
  1101. }
  1102. *__s = __cp;
  1103. }
  1104. return __retval;
  1105. }
  1106. __STRING_INLINE char *__strsep_3c (char **__s, char __reject1, char __reject2,
  1107. char __reject3);
  1108. __STRING_INLINE char *
  1109. __strsep_3c (char **__s, char __reject1, char __reject2, char __reject3)
  1110. {
  1111. register char *__retval = *__s;
  1112. if (__retval != NULL)
  1113. {
  1114. register char *__cp = __retval;
  1115. while (1)
  1116. {
  1117. if (*__cp == '\0')
  1118. {
  1119. __cp = NULL;
  1120. break;
  1121. }
  1122. if (*__cp == __reject1 || *__cp == __reject2 || *__cp == __reject3)
  1123. {
  1124. *__cp++ = '\0';
  1125. break;
  1126. }
  1127. ++__cp;
  1128. }
  1129. *__s = __cp;
  1130. }
  1131. return __retval;
  1132. }
  1133. # ifdef __USE_BSD
  1134. # define strsep(s, reject) __strsep (s, reject)
  1135. # endif
  1136. #endif
  1137. /* We need the memory allocation functions for inline strdup().
  1138. Referring to stdlib.h (even minimally) is not allowed
  1139. in any of the tight standards compliant modes. */
  1140. #ifdef __USE_MISC
  1141. # if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
  1142. # define __need_malloc_and_calloc
  1143. # include <stdlib.h>
  1144. # endif
  1145. # ifndef _HAVE_STRING_ARCH_strdup
  1146. extern char *__strdup (__const char *__string) __THROW __attribute_malloc__;
  1147. # define __strdup(s) \
  1148. (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
  1149. ? (((__const char *) (s))[0] == '\0' \
  1150. ? (char *) calloc (1, 1) \
  1151. : ({ size_t __len = strlen (s) + 1; \
  1152. char *__retval = (char *) malloc (__len); \
  1153. if (__retval != NULL) \
  1154. __retval = (char *) memcpy (__retval, s, __len); \
  1155. __retval; })) \
  1156. : __strdup (s)))
  1157. # if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  1158. # define strdup(s) __strdup (s)
  1159. # endif
  1160. # endif
  1161. # ifndef _HAVE_STRING_ARCH_strndup
  1162. extern char *__strndup (__const char *__string, size_t __n)
  1163. __THROW __attribute_malloc__;
  1164. # define __strndup(s, n) \
  1165. (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
  1166. ? (((__const char *) (s))[0] == '\0' \
  1167. ? (char *) calloc (1, 1) \
  1168. : ({ size_t __len = strlen (s) + 1; \
  1169. size_t __n = (n); \
  1170. char *__retval; \
  1171. if (__n < __len) \
  1172. __len = __n + 1; \
  1173. __retval = (char *) malloc (__len); \
  1174. if (__retval != NULL) \
  1175. { \
  1176. __retval[__len - 1] = '\0'; \
  1177. __retval = (char *) memcpy (__retval, s, \
  1178. __len - 1); \
  1179. } \
  1180. __retval; })) \
  1181. : __strndup (s, n)))
  1182. # ifdef __USE_GNU
  1183. # define strndup(s, n) __strndup (s, n)
  1184. # endif
  1185. # endif
  1186. #endif /* Use misc. or use GNU. */
  1187. #ifndef _FORCE_INLINES
  1188. # undef __STRING_INLINE
  1189. #endif
  1190. #endif /* No string inlines. */