wstring.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224
  1. /*
  2. * Copyright (C) 2002 Manuel Novoa III
  3. * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. /* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
  8. *
  9. * Besides uClibc, I'm using this code in my libc for elks, which is
  10. * a 16-bit environment with a fairly limited compiler. It would make
  11. * things much easier for me if this file isn't modified unnecessarily.
  12. * In particular, please put any new or replacement functions somewhere
  13. * else, and modify the makefile to use your version instead.
  14. * Thanks. Manuel
  15. *
  16. * ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! */
  17. /* Dec 20, 2002
  18. * Initial test implementation of strcoll, strxfrm, wcscoll, and wcsxfrm.
  19. * The code needs to be cleaned up a good bit, but I'd like to see people
  20. * test it out.
  21. *
  22. * Sep 11, 2003
  23. * Patch by Atsushi Nemoto <anemo@mba.ocn.ne.jp> to do arch-required
  24. * mapping of signal strings (alpha, mips, hppa, sparc).
  25. */
  26. #define _uintmaxtostr __libc__uintmaxtostr
  27. #define _GNU_SOURCE
  28. #include <features.h>
  29. #include <string.h>
  30. #include <strings.h>
  31. #include <stdio.h>
  32. #include <limits.h>
  33. #include <ctype.h>
  34. #include <stdlib.h>
  35. #include <errno.h>
  36. #include <signal.h>
  37. #include <assert.h>
  38. #include <locale.h>
  39. #include <bits/uClibc_uintmaxtostr.h>
  40. #ifdef WANT_WIDE
  41. #include <wchar.h>
  42. #include <wctype.h>
  43. #include <bits/uClibc_uwchar.h>
  44. #define Wvoid wchar_t
  45. #define Wchar wchar_t
  46. #define Wuchar __uwchar_t
  47. #define Wint wchar_t
  48. #else
  49. #define Wvoid void
  50. #define Wchar char
  51. typedef unsigned char __string_uchar_t;
  52. #define Wuchar __string_uchar_t
  53. #define Wint int
  54. #endif
  55. extern void *__memcpy (void *__restrict __dest,
  56. __const void *__restrict __src, size_t __n) attribute_hidden;
  57. extern void *__memmove (void *__dest, __const void *__src, size_t __n) attribute_hidden;
  58. extern void *__memset (void *__s, int __c, size_t __n) attribute_hidden;
  59. extern int __memcmp (__const void *__s1, __const void *__s2, size_t __n) attribute_hidden;
  60. extern size_t __strnlen (__const char *__string, size_t __maxlen) attribute_hidden;
  61. extern char *__strpbrk (__const char *__s, __const char *__accept) attribute_hidden;
  62. extern size_t __strspn (__const char *__s, __const char *__accept) attribute_hidden;
  63. extern char *__strsignal (int __sig) attribute_hidden;
  64. #ifdef WANT_WIDE
  65. extern wchar_t *__wcsdup (__const wchar_t *__s) attribute_hidden;
  66. extern size_t __wcslen (__const wchar_t *__s) attribute_hidden;
  67. extern wchar_t *__wcscpy (wchar_t *__restrict __dest,
  68. __const wchar_t *__restrict __src) attribute_hidden;
  69. extern size_t __wcsspn (__const wchar_t *__wcs, __const wchar_t *__accept) attribute_hidden;
  70. extern wchar_t *__wcspbrk (__const wchar_t *__wcs, __const wchar_t *__accept) attribute_hidden;
  71. #endif
  72. /**********************************************************************/
  73. /* NOTE: If we ever do internationalized syserr messages, this will
  74. * have to be changed! */
  75. #define _SYS_NERR 125
  76. #if defined(__mips__) || defined(__sparc__)
  77. /* sparce and mips have an extra error entry, as EDEADLK and EDEADLOCK have
  78. * different meanings on those platforms. */
  79. #undef _SYS_NERR
  80. #define _SYS_NERR 126
  81. #endif
  82. #ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
  83. #define _SYS_ERRMSG_MAXLEN 50
  84. #else /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
  85. #define _SYS_ERRMSG_MAXLEN 0
  86. #endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
  87. extern const char _string_syserrmsgs[];
  88. #define _SYS_NSIG 32
  89. #ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
  90. #define _SYS_SIGMSG_MAXLEN 25
  91. #else /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
  92. #define _SYS_SIGMSG_MAXLEN 0
  93. #endif /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
  94. extern const char _string_syssigmsgs[];
  95. #if _SYS_ERRMSG_MAXLEN < __UIM_BUFLEN_INT + 14
  96. #define _STRERROR_BUFSIZE (__UIM_BUFLEN_INT + 14)
  97. #else
  98. #define _STRERROR_BUFSIZE _SYS_ERRMSG_MAXLEN
  99. #endif
  100. #if _SYS_SIGMSG_MAXLEN < __UIM_BUFLEN_INT + 15
  101. #define _STRSIGNAL_BUFSIZE (__UIM_BUFLEN_INT + 15)
  102. #else
  103. #define _STRSIGNAL_BUFSIZE _SYS_SIGMSG_MAXLEN
  104. #endif
  105. /**********************************************************************/
  106. #if defined(L__string_syserrmsgs) && defined(__UCLIBC_HAS_ERRNO_MESSAGES__)
  107. const char _string_syserrmsgs[] = {
  108. /* 0: 0, 8 */ "Success\0"
  109. /* 1: 8, 24 */ "Operation not permitted\0"
  110. /* 2: 32, 26 */ "No such file or directory\0"
  111. /* 3: 58, 16 */ "No such process\0"
  112. /* 4: 74, 24 */ "Interrupted system call\0"
  113. /* 5: 98, 19 */ "Input/output error\0"
  114. /* 6: 117, 26 */ "No such device or address\0"
  115. /* 7: 143, 23 */ "Argument list too long\0"
  116. /* 8: 166, 18 */ "Exec format error\0"
  117. /* 9: 184, 20 */ "Bad file descriptor\0"
  118. /* 10: 204, 19 */ "No child processes\0"
  119. /* 11: 223, 33 */ "Resource temporarily unavailable\0"
  120. /* 12: 256, 23 */ "Cannot allocate memory\0"
  121. /* 13: 279, 18 */ "Permission denied\0"
  122. /* 14: 297, 12 */ "Bad address\0"
  123. /* 15: 309, 22 */ "Block device required\0"
  124. /* 16: 331, 24 */ "Device or resource busy\0"
  125. /* 17: 355, 12 */ "File exists\0"
  126. /* 18: 367, 26 */ "Invalid cross-device link\0"
  127. /* 19: 393, 15 */ "No such device\0"
  128. /* 20: 408, 16 */ "Not a directory\0"
  129. /* 21: 424, 15 */ "Is a directory\0"
  130. /* 22: 439, 17 */ "Invalid argument\0"
  131. /* 23: 456, 30 */ "Too many open files in system\0"
  132. /* 24: 486, 20 */ "Too many open files\0"
  133. /* 25: 506, 31 */ "Inappropriate ioctl for device\0"
  134. /* 26: 537, 15 */ "Text file busy\0"
  135. /* 27: 552, 15 */ "File too large\0"
  136. /* 28: 567, 24 */ "No space left on device\0"
  137. /* 29: 591, 13 */ "Illegal seek\0"
  138. /* 30: 604, 22 */ "Read-only file system\0"
  139. /* 31: 626, 15 */ "Too many links\0"
  140. /* 32: 641, 12 */ "Broken pipe\0"
  141. /* 33: 653, 33 */ "Numerical argument out of domain\0"
  142. /* 34: 686, 30 */ "Numerical result out of range\0"
  143. /* 35: 716, 26 */ "Resource deadlock avoided\0"
  144. /* 36: 742, 19 */ "File name too long\0"
  145. /* 37: 761, 19 */ "No locks available\0"
  146. /* 38: 780, 25 */ "Function not implemented\0"
  147. /* 39: 805, 20 */ "Directory not empty\0"
  148. /* 40: 825, 34 */ "Too many levels of symbolic links\0"
  149. /* 41: 859, 1 */ "\0"
  150. /* 42: 860, 27 */ "No message of desired type\0"
  151. /* 43: 887, 19 */ "Identifier removed\0"
  152. /* 44: 906, 28 */ "Channel number out of range\0"
  153. /* 45: 934, 25 */ "Level 2 not synchronized\0"
  154. /* 46: 959, 15 */ "Level 3 halted\0"
  155. /* 47: 974, 14 */ "Level 3 reset\0"
  156. /* 48: 988, 25 */ "Link number out of range\0"
  157. /* 49: 1013, 29 */ "Protocol driver not attached\0"
  158. /* 50: 1042, 27 */ "No CSI structure available\0"
  159. /* 51: 1069, 15 */ "Level 2 halted\0"
  160. /* 52: 1084, 17 */ "Invalid exchange\0"
  161. /* 53: 1101, 27 */ "Invalid request descriptor\0"
  162. /* 54: 1128, 14 */ "Exchange full\0"
  163. /* 55: 1142, 9 */ "No anode\0"
  164. /* 56: 1151, 21 */ "Invalid request code\0"
  165. /* 57: 1172, 13 */ "Invalid slot\0"
  166. /* 58: 1185, 1 */ "\0"
  167. /* 59: 1186, 21 */ "Bad font file format\0"
  168. /* 60: 1207, 20 */ "Device not a stream\0"
  169. /* 61: 1227, 18 */ "No data available\0"
  170. /* 62: 1245, 14 */ "Timer expired\0"
  171. /* 63: 1259, 25 */ "Out of streams resources\0"
  172. /* 64: 1284, 30 */ "Machine is not on the network\0"
  173. /* 65: 1314, 22 */ "Package not installed\0"
  174. /* 66: 1336, 17 */ "Object is remote\0"
  175. /* 67: 1353, 22 */ "Link has been severed\0"
  176. /* 68: 1375, 16 */ "Advertise error\0"
  177. /* 69: 1391, 14 */ "Srmount error\0"
  178. /* 70: 1405, 28 */ "Communication error on send\0"
  179. /* 71: 1433, 15 */ "Protocol error\0"
  180. /* 72: 1448, 19 */ "Multihop attempted\0"
  181. /* 73: 1467, 19 */ "RFS specific error\0"
  182. /* 74: 1486, 12 */ "Bad message\0"
  183. /* 75: 1498, 38 */ "Value too large for defined data type\0"
  184. /* 76: 1536, 27 */ "Name not unique on network\0"
  185. /* 77: 1563, 29 */ "File descriptor in bad state\0"
  186. /* 78: 1592, 23 */ "Remote address changed\0"
  187. /* 79: 1615, 39 */ "Can not access a needed shared library\0"
  188. /* 80: 1654, 37 */ "Accessing a corrupted shared library\0"
  189. /* 81: 1691, 32 */ ".lib section in a.out corrupted\0"
  190. /* 82: 1723, 48 */ "Attempting to link in too many shared libraries\0"
  191. /* 83: 1771, 38 */ "Cannot exec a shared library directly\0"
  192. /* 84: 1809, 50 */ "Invalid or incomplete multibyte or wide character\0"
  193. /* 85: 1859, 44 */ "Interrupted system call should be restarted\0"
  194. /* 86: 1903, 19 */ "Streams pipe error\0"
  195. /* 87: 1922, 15 */ "Too many users\0"
  196. /* 88: 1937, 31 */ "Socket operation on non-socket\0"
  197. /* 89: 1968, 29 */ "Destination address required\0"
  198. /* 90: 1997, 17 */ "Message too long\0"
  199. /* 91: 2014, 31 */ "Protocol wrong type for socket\0"
  200. /* 92: 2045, 23 */ "Protocol not available\0"
  201. /* 93: 2068, 23 */ "Protocol not supported\0"
  202. /* 94: 2091, 26 */ "Socket type not supported\0"
  203. /* 95: 2117, 24 */ "Operation not supported\0"
  204. /* 96: 2141, 30 */ "Protocol family not supported\0"
  205. /* 97: 2171, 41 */ "Address family not supported by protocol\0"
  206. /* 98: 2212, 23 */ "Address already in use\0"
  207. /* 99: 2235, 32 */ "Cannot assign requested address\0"
  208. /* 100: 2267, 16 */ "Network is down\0"
  209. /* 101: 2283, 23 */ "Network is unreachable\0"
  210. /* 102: 2306, 36 */ "Network dropped connection on reset\0"
  211. /* 103: 2342, 33 */ "Software caused connection abort\0"
  212. /* 104: 2375, 25 */ "Connection reset by peer\0"
  213. /* 105: 2400, 26 */ "No buffer space available\0"
  214. /* 106: 2426, 40 */ "Transport endpoint is already connected\0"
  215. /* 107: 2466, 36 */ "Transport endpoint is not connected\0"
  216. /* 108: 2502, 46 */ "Cannot send after transport endpoint shutdown\0"
  217. /* 109: 2548, 35 */ "Too many references: cannot splice\0"
  218. /* 110: 2583, 21 */ "Connection timed out\0"
  219. /* 111: 2604, 19 */ "Connection refused\0"
  220. /* 112: 2623, 13 */ "Host is down\0"
  221. /* 113: 2636, 17 */ "No route to host\0"
  222. /* 114: 2653, 30 */ "Operation already in progress\0"
  223. /* 115: 2683, 26 */ "Operation now in progress\0"
  224. /* 116: 2709, 22 */ "Stale NFS file handle\0"
  225. /* 117: 2731, 25 */ "Structure needs cleaning\0"
  226. /* 118: 2756, 28 */ "Not a XENIX named type file\0"
  227. /* 119: 2784, 30 */ "No XENIX semaphores available\0"
  228. /* 120: 2814, 21 */ "Is a named type file\0"
  229. /* 121: 2835, 17 */ "Remote I/O error\0"
  230. /* 122: 2852, 20 */ "Disk quota exceeded\0"
  231. /* 123: 2872, 16 */ "No medium found\0"
  232. /* 124: 2888, 18 */ "Wrong medium type"
  233. #if defined(__mips__) || defined(__sparc__)
  234. "\0"
  235. /* 125: 2906, 28 */ "File locking deadlock error"
  236. #endif
  237. /* Note: for mips we are ignoring ECANCELED since glibc doesn't have a
  238. * corresponsding message.*/
  239. };
  240. #endif
  241. /**********************************************************************/
  242. #if defined(L_sys_errlist) && defined(__UCLIBC_HAS_SYS_ERRLIST__)
  243. link_warning(_sys_errlist, "sys_nerr and sys_errlist are obsolete and uClibc support for them (in at least some configurations) will probably be unavailable in the near future.")
  244. const char *const sys_errlist[] = {
  245. [0] = _string_syserrmsgs + 0,
  246. [EPERM] = _string_syserrmsgs + 8,
  247. [ENOENT] = _string_syserrmsgs + 32,
  248. [ESRCH] = _string_syserrmsgs + 58,
  249. [EINTR] = _string_syserrmsgs + 74,
  250. [EIO] = _string_syserrmsgs + 98,
  251. [ENXIO] = _string_syserrmsgs + 117,
  252. [E2BIG] = _string_syserrmsgs + 143,
  253. [ENOEXEC] = _string_syserrmsgs + 166,
  254. [EBADF] = _string_syserrmsgs + 184,
  255. [ECHILD] = _string_syserrmsgs + 204,
  256. [EAGAIN] = _string_syserrmsgs + 223,
  257. [ENOMEM] = _string_syserrmsgs + 256,
  258. [EACCES] = _string_syserrmsgs + 279,
  259. [EFAULT] = _string_syserrmsgs + 297,
  260. [ENOTBLK] = _string_syserrmsgs + 309,
  261. [EBUSY] = _string_syserrmsgs + 331,
  262. [EEXIST] = _string_syserrmsgs + 355,
  263. [EXDEV] = _string_syserrmsgs + 367,
  264. [ENODEV] = _string_syserrmsgs + 393,
  265. [ENOTDIR] = _string_syserrmsgs + 408,
  266. [EISDIR] = _string_syserrmsgs + 424,
  267. [EINVAL] = _string_syserrmsgs + 439,
  268. [ENFILE] = _string_syserrmsgs + 456,
  269. [EMFILE] = _string_syserrmsgs + 486,
  270. [ENOTTY] = _string_syserrmsgs + 506,
  271. [ETXTBSY] = _string_syserrmsgs + 537,
  272. [EFBIG] = _string_syserrmsgs + 552,
  273. [ENOSPC] = _string_syserrmsgs + 567,
  274. [ESPIPE] = _string_syserrmsgs + 591,
  275. [EROFS] = _string_syserrmsgs + 604,
  276. [EMLINK] = _string_syserrmsgs + 626,
  277. [EPIPE] = _string_syserrmsgs + 641,
  278. [EDOM] = _string_syserrmsgs + 653,
  279. [ERANGE] = _string_syserrmsgs + 686,
  280. [EDEADLK] = _string_syserrmsgs + 716,
  281. [ENAMETOOLONG] = _string_syserrmsgs + 742,
  282. [ENOLCK] = _string_syserrmsgs + 761,
  283. [ENOSYS] = _string_syserrmsgs + 780,
  284. [ENOTEMPTY] = _string_syserrmsgs + 805,
  285. [ELOOP] = _string_syserrmsgs + 825,
  286. /* _string_syserrmsgs + 859, */
  287. [ENOMSG] = _string_syserrmsgs + 860,
  288. [EIDRM] = _string_syserrmsgs + 887,
  289. [ECHRNG] = _string_syserrmsgs + 906,
  290. [EL2NSYNC] = _string_syserrmsgs + 934,
  291. [EL3HLT] = _string_syserrmsgs + 959,
  292. [EL3RST] = _string_syserrmsgs + 974,
  293. [ELNRNG] = _string_syserrmsgs + 988,
  294. [EUNATCH] = _string_syserrmsgs + 1013,
  295. [ENOCSI] = _string_syserrmsgs + 1042,
  296. [EL2HLT] = _string_syserrmsgs + 1069,
  297. [EBADE] = _string_syserrmsgs + 1084,
  298. [EBADR] = _string_syserrmsgs + 1101,
  299. [EXFULL] = _string_syserrmsgs + 1128,
  300. [ENOANO] = _string_syserrmsgs + 1142,
  301. [EBADRQC] = _string_syserrmsgs + 1151,
  302. [EBADSLT] = _string_syserrmsgs + 1172,
  303. /* _string_syserrmsgs + 1185, */
  304. [EBFONT] = _string_syserrmsgs + 1186,
  305. [ENOSTR] = _string_syserrmsgs + 1207,
  306. [ENODATA] = _string_syserrmsgs + 1227,
  307. [ETIME] = _string_syserrmsgs + 1245,
  308. [ENOSR] = _string_syserrmsgs + 1259,
  309. [ENONET] = _string_syserrmsgs + 1284,
  310. [ENOPKG] = _string_syserrmsgs + 1314,
  311. [EREMOTE] = _string_syserrmsgs + 1336,
  312. [ENOLINK] = _string_syserrmsgs + 1353,
  313. [EADV] = _string_syserrmsgs + 1375,
  314. [ESRMNT] = _string_syserrmsgs + 1391,
  315. [ECOMM] = _string_syserrmsgs + 1405,
  316. [EPROTO] = _string_syserrmsgs + 1433,
  317. [EMULTIHOP] = _string_syserrmsgs + 1448,
  318. [EDOTDOT] = _string_syserrmsgs + 1467,
  319. [EBADMSG] = _string_syserrmsgs + 1486,
  320. [EOVERFLOW] = _string_syserrmsgs + 1498,
  321. [ENOTUNIQ] = _string_syserrmsgs + 1536,
  322. [EBADFD] = _string_syserrmsgs + 1563,
  323. [EREMCHG] = _string_syserrmsgs + 1592,
  324. [ELIBACC] = _string_syserrmsgs + 1615,
  325. [ELIBBAD] = _string_syserrmsgs + 1654,
  326. [ELIBSCN] = _string_syserrmsgs + 1691,
  327. [ELIBMAX] = _string_syserrmsgs + 1723,
  328. [ELIBEXEC] = _string_syserrmsgs + 1771,
  329. [EILSEQ] = _string_syserrmsgs + 1809,
  330. [ERESTART] = _string_syserrmsgs + 1859,
  331. [ESTRPIPE] = _string_syserrmsgs + 1903,
  332. [EUSERS] = _string_syserrmsgs + 1922,
  333. [ENOTSOCK] = _string_syserrmsgs + 1937,
  334. [EDESTADDRREQ] = _string_syserrmsgs + 1968,
  335. [EMSGSIZE] = _string_syserrmsgs + 1997,
  336. [EPROTOTYPE] = _string_syserrmsgs + 2014,
  337. [ENOPROTOOPT] = _string_syserrmsgs + 2045,
  338. [EPROTONOSUPPORT] = _string_syserrmsgs + 2068,
  339. [ESOCKTNOSUPPORT] = _string_syserrmsgs + 2091,
  340. [EOPNOTSUPP] = _string_syserrmsgs + 2117,
  341. [EPFNOSUPPORT] = _string_syserrmsgs + 2141,
  342. [EAFNOSUPPORT] = _string_syserrmsgs + 2171,
  343. [EADDRINUSE] = _string_syserrmsgs + 2212,
  344. [EADDRNOTAVAIL] = _string_syserrmsgs + 2235,
  345. [ENETDOWN] = _string_syserrmsgs + 2267,
  346. [ENETUNREACH] = _string_syserrmsgs + 2283,
  347. [ENETRESET] = _string_syserrmsgs + 2306,
  348. [ECONNABORTED] = _string_syserrmsgs + 2342,
  349. [ECONNRESET] = _string_syserrmsgs + 2375,
  350. [ENOBUFS] = _string_syserrmsgs + 2400,
  351. [EISCONN] = _string_syserrmsgs + 2426,
  352. [ENOTCONN] = _string_syserrmsgs + 2466,
  353. [ESHUTDOWN] = _string_syserrmsgs + 2502,
  354. [ETOOMANYREFS] = _string_syserrmsgs + 2548,
  355. [ETIMEDOUT] = _string_syserrmsgs + 2583,
  356. [ECONNREFUSED] = _string_syserrmsgs + 2604,
  357. [EHOSTDOWN] = _string_syserrmsgs + 2623,
  358. [EHOSTUNREACH] = _string_syserrmsgs + 2636,
  359. [EALREADY] = _string_syserrmsgs + 2653,
  360. [EINPROGRESS] = _string_syserrmsgs + 2683,
  361. [ESTALE] = _string_syserrmsgs + 2709,
  362. [EUCLEAN] = _string_syserrmsgs + 2731,
  363. [ENOTNAM] = _string_syserrmsgs + 2756,
  364. [ENAVAIL] = _string_syserrmsgs + 2784,
  365. [EISNAM] = _string_syserrmsgs + 2814,
  366. [EREMOTEIO] = _string_syserrmsgs + 2835,
  367. [EDQUOT] = _string_syserrmsgs + 2852,
  368. [ENOMEDIUM] = _string_syserrmsgs + 2872,
  369. [EMEDIUMTYPE] = _string_syserrmsgs + 2888,
  370. #if EDEADLOCK != EDEADLK
  371. [EDEADLOCK] = _string_syserrmsgs + 2906,
  372. #endif
  373. #if EWOULDBLOCK != EAGAIN
  374. #error EWOULDBLOCK does not equal EAGAIN
  375. #endif
  376. /* For now, ignore the other arch-specific errors. glibc only maps EPROCLIM. */
  377. /* some other mips errors */
  378. #ifdef ECANCELED
  379. #endif
  380. #ifdef EINIT
  381. #endif
  382. #ifdef EREMDEV
  383. #endif
  384. /* some other sparc errors */
  385. #ifdef EPROCLIM
  386. #endif
  387. #ifdef ERREMOTE
  388. #endif
  389. };
  390. int sys_nerr = sizeof(sys_errlist)/sizeof(sys_errlist[0]);
  391. #endif
  392. /**********************************************************************/
  393. #if 0
  394. #ifdef L_wmemcpy
  395. #define L_memcpy
  396. #define Wmemcpy wmemcpy
  397. #else
  398. #define Wmemcpy memcpy
  399. #endif
  400. #endif
  401. #ifdef L_memcpy
  402. #ifndef WANT_WIDE
  403. #undef memcpy
  404. #else
  405. #undef wmemcpy
  406. #endif
  407. Wvoid attribute_hidden *Wmemcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
  408. {
  409. register Wchar *r1 = s1;
  410. register const Wchar *r2 = s2;
  411. #ifdef __BCC__
  412. while (n--) {
  413. *r1++ = *r2++;
  414. }
  415. #else
  416. while (n) {
  417. *r1++ = *r2++;
  418. --n;
  419. }
  420. #endif
  421. return s1;
  422. }
  423. #endif
  424. /**********************************************************************/
  425. #if 0
  426. #ifdef L_wmemmove
  427. #define L_memmove
  428. #define Wmemmove wmemmove
  429. #else
  430. #define Wmemmove memmove
  431. #endif
  432. #endif
  433. #ifdef L_memmove
  434. #ifndef WANT_WIDE
  435. #undef memmove
  436. #else
  437. #undef wmemmove
  438. #endif
  439. Wvoid attribute_hidden *Wmemmove(Wvoid *s1, const Wvoid *s2, size_t n)
  440. {
  441. #ifdef __BCC__
  442. register Wchar *s = (Wchar *) s1;
  443. register const Wchar *p = (const Wchar *) s2;
  444. if (p >= s) {
  445. while (n--) {
  446. *s++ = *p++;
  447. }
  448. } else {
  449. s += n;
  450. p += n;
  451. while (n--) {
  452. *--s = *--p;
  453. }
  454. }
  455. return s1;
  456. #else
  457. register Wchar *s = (Wchar *) s1;
  458. register const Wchar *p = (const Wchar *) s2;
  459. if (p >= s) {
  460. while (n) {
  461. *s++ = *p++;
  462. --n;
  463. }
  464. } else {
  465. while (n) {
  466. --n;
  467. s[n] = p[n];
  468. }
  469. }
  470. return s1;
  471. #endif
  472. }
  473. #endif
  474. /**********************************************************************/
  475. #if 0
  476. #ifdef L_wcscpy
  477. #define L_strcpy
  478. #define Wstrcpy wcscpy
  479. #else
  480. #define Wstrcpy strcpy
  481. #endif
  482. #endif
  483. #ifdef L_strcpy
  484. #ifndef WANT_WIDE
  485. #undef strcpy
  486. #else
  487. #undef wcscpy
  488. #endif
  489. Wchar attribute_hidden *Wstrcpy(Wchar * __restrict s1, const Wchar * __restrict s2)
  490. {
  491. register Wchar *s = s1;
  492. #ifdef __BCC__
  493. do {
  494. *s = *s2++;
  495. } while (*s++ != 0);
  496. #else
  497. while ( (*s++ = *s2++) != 0 );
  498. #endif
  499. return s1;
  500. }
  501. #endif
  502. /**********************************************************************/
  503. #if 0
  504. #ifdef L_wcsncpy
  505. #define L_strncpy
  506. #define Wstrncpy wcsncpy
  507. #else
  508. #define Wstrncpy strncpy
  509. #endif
  510. #endif
  511. #ifdef L_strncpy
  512. #ifndef WANT_WIDE
  513. #undef strncpy
  514. #else
  515. #undef wcsncpy
  516. #endif
  517. Wchar attribute_hidden *Wstrncpy(Wchar * __restrict s1, register const Wchar * __restrict s2,
  518. size_t n)
  519. {
  520. register Wchar *s = s1;
  521. #ifdef __BCC__
  522. while (n--) {
  523. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  524. ++s;
  525. }
  526. #else
  527. while (n) {
  528. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  529. ++s;
  530. --n;
  531. }
  532. #endif
  533. return s1;
  534. }
  535. #endif
  536. /**********************************************************************/
  537. #if 0
  538. #ifdef L_wcscat
  539. #define L_strcat
  540. #define Wstrcat wcscat
  541. #else
  542. #define Wstrcat strcat
  543. #endif
  544. #endif
  545. #ifdef L_strcat
  546. #ifndef WANT_WIDE
  547. #undef strcat
  548. #else
  549. #undef wcscat
  550. #endif
  551. Wchar attribute_hidden *Wstrcat(Wchar * __restrict s1, register const Wchar * __restrict s2)
  552. {
  553. register Wchar *s = s1;
  554. while (*s++);
  555. --s;
  556. while ((*s++ = *s2++) != 0);
  557. return s1;
  558. }
  559. #endif
  560. /**********************************************************************/
  561. #if 0
  562. #ifdef L_wcsncat
  563. #define L_strncat
  564. #define Wstrncat wcsncat
  565. #else
  566. #define Wstrncat strncat
  567. #endif
  568. #endif
  569. #ifdef L_strncat
  570. #ifndef WANT_WIDE
  571. #undef strncat
  572. #else
  573. #undef wcsncat
  574. #endif
  575. Wchar attribute_hidden *Wstrncat(Wchar * __restrict s1, register const Wchar * __restrict s2,
  576. size_t n)
  577. {
  578. register Wchar *s = s1;
  579. while (*s++);
  580. --s;
  581. #if __BCC__
  582. while (n-- && ((*s = *s2++) != 0)) ++s;
  583. #else
  584. while (n && ((*s = *s2++) != 0)) {
  585. --n;
  586. ++s;
  587. }
  588. #endif
  589. *s = 0;
  590. return s1;
  591. }
  592. #endif
  593. /**********************************************************************/
  594. #if 0
  595. #ifdef L_wmemcmp
  596. #define L_memcmp
  597. #define Wmemcmp wmemcmp
  598. #else
  599. #define Wmemcmp memcmp
  600. #endif
  601. #endif
  602. #ifdef L_memcmp
  603. #ifndef WANT_WIDE
  604. #undef memcmp
  605. #else
  606. #undef wmemcmp
  607. #endif
  608. int attribute_hidden Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n)
  609. {
  610. register const Wuchar *r1 = (const Wuchar *) s1;
  611. register const Wuchar *r2 = (const Wuchar *) s2;
  612. #ifdef WANT_WIDE
  613. while (n && (*r1 == *r2)) {
  614. ++r1;
  615. ++r2;
  616. --n;
  617. }
  618. return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);
  619. #else
  620. int r = 0;
  621. while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0));
  622. return r;
  623. #endif
  624. }
  625. #if 0 /* ndef L_wmemcmp */
  626. weak_alias(memcmp, bcmp)
  627. #endif
  628. #endif
  629. /**********************************************************************/
  630. #if 0
  631. #ifdef L_wcscmp
  632. #define L_strcmp
  633. #define Wstrcmp wcscmp
  634. #else
  635. #define Wstrcmp strcmp
  636. #endif
  637. #endif
  638. #ifdef L_strcmp
  639. #ifndef WANT_WIDE
  640. #undef strcmp
  641. #else
  642. #undef wcscmp
  643. #endif
  644. int attribute_hidden Wstrcmp(register const Wchar *s1, register const Wchar *s2)
  645. {
  646. #ifdef WANT_WIDE
  647. while (*((Wuchar *)s1) == *((Wuchar *)s2)) {
  648. if (!*s1++) {
  649. return 0;
  650. }
  651. ++s2;
  652. }
  653. return (*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1;
  654. #else
  655. int r;
  656. while (((r = ((int)(*((Wuchar *)s1))) - *((Wuchar *)s2++))
  657. == 0) && *s1++);
  658. return r;
  659. #endif
  660. }
  661. #if 0 /* def __LOCALE_C_ONLY */
  662. #ifdef L_wcscmp
  663. weak_alias(wcscmp, wcscoll)
  664. #else /* L_wcscmp */
  665. weak_alias(strcmp, strcoll)
  666. #endif /* L_wcscmp */
  667. #endif /* __LOCALE_C_ONLY */
  668. #endif
  669. /**********************************************************************/
  670. #if 0
  671. #ifdef L_wcsncmp
  672. #define L_strncmp
  673. #define Wstrncmp wcsncmp
  674. #else
  675. #define Wstrncmp strncmp
  676. #endif
  677. #endif
  678. #ifdef L_strncmp
  679. #ifndef WANT_WIDE
  680. #undef strncmp
  681. #else
  682. #undef wcsncmp
  683. #endif
  684. int attribute_hidden Wstrncmp(register const Wchar *s1, register const Wchar *s2, size_t n)
  685. {
  686. #ifdef WANT_WIDE
  687. while (n && (*((Wuchar *)s1) == *((Wuchar *)s2))) {
  688. if (!*s1++) {
  689. return 0;
  690. }
  691. ++s2;
  692. --n;
  693. }
  694. return (n == 0) ? 0 : ((*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1);
  695. #else
  696. int r = 0;
  697. while (n--
  698. && ((r = ((int)(*((unsigned char *)s1))) - *((unsigned char *)s2++))
  699. == 0)
  700. && *s1++);
  701. return r;
  702. #endif
  703. }
  704. #endif
  705. /**********************************************************************/
  706. #if 0
  707. #ifdef L_wmemchr
  708. #define L_memchr
  709. #define Wmemchr wmemchr
  710. #else
  711. #define Wmemchr memchr
  712. #endif
  713. #endif
  714. #ifdef L_memchr
  715. #ifndef WANT_WIDE
  716. #undef memchr
  717. #else
  718. #undef wmemchr
  719. #endif
  720. Wvoid attribute_hidden *Wmemchr(const Wvoid *s, Wint c, size_t n)
  721. {
  722. register const Wuchar *r = (const Wuchar *) s;
  723. #ifdef __BCC__
  724. /* bcc can optimize the counter if it thinks it is a pointer... */
  725. register const char *np = (const char *) n;
  726. #else
  727. #define np n
  728. #endif
  729. while (np) {
  730. if (*r == ((Wuchar)c)) {
  731. return (Wvoid *) r; /* silence the warning */
  732. }
  733. ++r;
  734. --np;
  735. }
  736. return NULL;
  737. }
  738. #undef np
  739. #endif
  740. /**********************************************************************/
  741. #if 0
  742. #ifdef L_wcschr
  743. #define L_strchr
  744. #define Wstrchr wcschr
  745. #else
  746. #define Wstrchr strchr
  747. #endif
  748. #endif
  749. #ifdef L_strchr
  750. #ifndef WANT_WIDE
  751. #undef strchr
  752. #else
  753. #undef wcschr
  754. #endif
  755. Wchar attribute_hidden *Wstrchr(register const Wchar *s, Wint c)
  756. {
  757. do {
  758. if (*s == ((Wchar)c)) {
  759. return (Wchar *) s; /* silence the warning */
  760. }
  761. } while (*s++);
  762. return NULL;
  763. }
  764. #if 0 /* ndef L_wcschr */
  765. weak_alias(strchr, index)
  766. #endif
  767. #endif
  768. /**********************************************************************/
  769. #if 0
  770. #ifdef L_wcscspn
  771. #define L_strcspn
  772. #define Wstrcspn wcscspn
  773. #else
  774. #define Wstrcspn strcspn
  775. #endif
  776. #endif
  777. #ifdef L_strcspn
  778. #ifndef WANT_WIDE
  779. #undef strcspn
  780. #else
  781. #undef wcscspn
  782. #endif
  783. size_t attribute_hidden Wstrcspn(const Wchar *s1, const Wchar *s2)
  784. {
  785. register const Wchar *s;
  786. register const Wchar *p;
  787. for ( s=s1 ; *s ; s++ ) {
  788. for ( p=s2 ; *p ; p++ ) {
  789. if (*p == *s) goto done;
  790. }
  791. }
  792. done:
  793. return s - s1;
  794. }
  795. #endif
  796. /**********************************************************************/
  797. #if 0
  798. #ifdef L_wcspbrk
  799. #define L_strpbrk
  800. #define Wstrpbrk wcspbrk
  801. #else
  802. #define Wstrpbrk strpbrk
  803. #endif
  804. #endif
  805. #ifdef L_strpbrk
  806. #ifndef WANT_WIDE
  807. #undef strpbrk
  808. #else
  809. #undef wcspbrk
  810. #endif
  811. Wchar attribute_hidden *Wstrpbrk(const Wchar *s1, const Wchar *s2)
  812. {
  813. register const Wchar *s;
  814. register const Wchar *p;
  815. for ( s=s1 ; *s ; s++ ) {
  816. for ( p=s2 ; *p ; p++ ) {
  817. if (*p == *s) return (Wchar *) s; /* silence the warning */
  818. }
  819. }
  820. return NULL;
  821. }
  822. #endif
  823. /**********************************************************************/
  824. #if 0
  825. #ifdef L_wcsrchr
  826. #define L_strrchr
  827. #define Wstrrchr wcsrchr
  828. #else
  829. #define Wstrrchr strrchr
  830. #endif
  831. #endif
  832. #ifdef L_strrchr
  833. #ifndef WANT_WIDE
  834. #undef strrchr
  835. #else
  836. #undef wcsrchr
  837. #endif
  838. Wchar attribute_hidden *Wstrrchr(register const Wchar *s, Wint c)
  839. {
  840. register const Wchar *p;
  841. p = NULL;
  842. do {
  843. if (*s == (Wchar) c) {
  844. p = s;
  845. }
  846. } while (*s++);
  847. return (Wchar *) p; /* silence the warning */
  848. }
  849. #if 0 /* ndef L_wcsrchr */
  850. weak_alias(strrchr, rindex)
  851. #endif
  852. #endif
  853. /**********************************************************************/
  854. #if 0
  855. #ifdef L_wcsspn
  856. #define L_strspn
  857. #define Wstrspn wcsspn
  858. #else
  859. #define Wstrspn strspn
  860. #endif
  861. #endif
  862. #ifdef L_strspn
  863. #ifndef WANT_WIDE
  864. #undef strspn
  865. #else
  866. #undef wcsspn
  867. #endif
  868. size_t attribute_hidden Wstrspn(const Wchar *s1, const Wchar *s2)
  869. {
  870. register const Wchar *s = s1;
  871. register const Wchar *p = s2;
  872. while (*p) {
  873. if (*p++ == *s) {
  874. ++s;
  875. p = s2;
  876. }
  877. }
  878. return s - s1;
  879. }
  880. #endif
  881. /**********************************************************************/
  882. #if 0
  883. #ifdef L_wcsstr
  884. #define L_strstr
  885. #define Wstrstr wcsstr
  886. #else
  887. #define Wstrstr strstr
  888. #endif
  889. #endif
  890. #ifdef L_strstr
  891. /* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
  892. #ifndef WANT_WIDE
  893. #undef strstr
  894. #else
  895. #undef wcsstr
  896. #endif
  897. Wchar attribute_hidden *Wstrstr(const Wchar *s1, const Wchar *s2)
  898. {
  899. register const Wchar *s = s1;
  900. register const Wchar *p = s2;
  901. do {
  902. if (!*p) {
  903. return (Wchar *) s1;;
  904. }
  905. if (*p == *s) {
  906. ++p;
  907. ++s;
  908. } else {
  909. p = s2;
  910. if (!*s) {
  911. return NULL;
  912. }
  913. s = ++s1;
  914. }
  915. } while (1);
  916. }
  917. #if 0 /* def L_wcsstr */
  918. weak_alias(wcsstr, wcswcs)
  919. #endif
  920. #endif
  921. /**********************************************************************/
  922. #if 0
  923. #undef Wstrspn
  924. #undef Wstrpbrk
  925. #ifdef L_wcstok
  926. #define L_strtok_r
  927. #define Wstrtok_r wcstok
  928. #define Wstrspn wcsspn
  929. #define Wstrpbrk wcspbrk
  930. #else
  931. #define Wstrtok_r __strtok_r
  932. #define Wstrspn strspn
  933. #define Wstrpbrk strpbrk
  934. #endif
  935. #endif
  936. #ifdef L_strtok_r
  937. #ifndef WANT_WIDE
  938. #undef strtok_r
  939. #else
  940. #undef wcstok
  941. #endif
  942. Wchar attribute_hidden *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
  943. Wchar ** __restrict next_start)
  944. {
  945. register Wchar *s;
  946. register Wchar *p;
  947. #if 1
  948. if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
  949. if (*(s += Wstrspn(s, s2))) {
  950. if ((p = Wstrpbrk(s, s2)) != NULL) {
  951. *p++ = 0;
  952. }
  953. } else {
  954. p = s = NULL;
  955. }
  956. *next_start = p;
  957. }
  958. return s;
  959. #else
  960. if (!(s = s1)) {
  961. s = *next_start;
  962. }
  963. if (s && *(s += Wstrspn(s, s2))) {
  964. if (*(p = s + Wstrcspn(s, s2))) {
  965. *p++ = 0;
  966. }
  967. *next_start = p;
  968. return s;
  969. }
  970. return NULL; /* TODO: set *next_start = NULL for safety? */
  971. #endif
  972. }
  973. #if 0 /* ndef L_wcstok */
  974. weak_alias(__strtok_r, strtok_r)
  975. #endif
  976. #endif
  977. /**********************************************************************/
  978. /* #ifdef L_wcstok */
  979. /* #define L_strtok */
  980. /* #define Wstrtok wcstok */
  981. /* #define Wstrtok_r wcstok_r */
  982. /* #else */
  983. /* #define Wstrtok strtok */
  984. /* #define Wstrtok_r strtok_r */
  985. /* #endif */
  986. #ifdef L_strtok
  987. #define Wstrtok strtok
  988. #define Wstrtok_r __strtok_r
  989. Wchar *Wstrtok(Wchar * __restrict s1, const Wchar * __restrict s2)
  990. {
  991. static Wchar *next_start; /* Initialized to 0 since in bss. */
  992. return Wstrtok_r(s1, s2, &next_start);
  993. }
  994. #endif
  995. /**********************************************************************/
  996. #if 0
  997. #ifdef L_wmemset
  998. #define L_memset
  999. #define Wmemset wmemset
  1000. #else
  1001. #define Wmemset memset
  1002. #endif
  1003. #endif
  1004. #ifdef L_memset
  1005. #ifndef WANT_WIDE
  1006. #undef memset
  1007. #else
  1008. #undef wmemset
  1009. #endif
  1010. Wvoid attribute_hidden *Wmemset(Wvoid *s, Wint c, size_t n)
  1011. {
  1012. register Wuchar *p = (Wuchar *) s;
  1013. #ifdef __BCC__
  1014. /* bcc can optimize the counter if it thinks it is a pointer... */
  1015. register const char *np = (const char *) n;
  1016. #else
  1017. #define np n
  1018. #endif
  1019. while (np) {
  1020. *p++ = (Wuchar) c;
  1021. --np;
  1022. }
  1023. return s;
  1024. }
  1025. #undef np
  1026. #endif
  1027. /**********************************************************************/
  1028. #if 0
  1029. #ifdef L_wcslen
  1030. #define L_strlen
  1031. #define Wstrlen wcslen
  1032. #else
  1033. #define Wstrlen strlen
  1034. #endif
  1035. #endif
  1036. #ifdef L_strlen
  1037. #ifndef WANT_WIDE
  1038. #undef strlen
  1039. #else
  1040. #undef wcslen
  1041. #endif
  1042. size_t attribute_hidden Wstrlen(const Wchar *s)
  1043. {
  1044. register const Wchar *p;
  1045. for (p=s ; *p ; p++);
  1046. return p - s;
  1047. }
  1048. #endif
  1049. /**********************************************************************/
  1050. /* ANSI/ISO end here */
  1051. /**********************************************************************/
  1052. #ifdef L_ffs
  1053. #undef ffs
  1054. int attribute_hidden __ffs(int i)
  1055. {
  1056. #if 1
  1057. /* inlined binary search method */
  1058. char n = 1;
  1059. #if UINT_MAX == 0xffffU
  1060. /* nothing to do here -- just trying to avoiding possible problems */
  1061. #elif UINT_MAX == 0xffffffffU
  1062. if (!(i & 0xffff)) {
  1063. n += 16;
  1064. i >>= 16;
  1065. }
  1066. #else
  1067. #error ffs needs rewriting!
  1068. #endif
  1069. if (!(i & 0xff)) {
  1070. n += 8;
  1071. i >>= 8;
  1072. }
  1073. if (!(i & 0x0f)) {
  1074. n += 4;
  1075. i >>= 4;
  1076. }
  1077. if (!(i & 0x03)) {
  1078. n += 2;
  1079. i >>= 2;
  1080. }
  1081. return (i) ? (n + ((i+1) & 0x01)) : 0;
  1082. #else
  1083. /* linear search -- slow, but small */
  1084. int n;
  1085. for (n = 0 ; i ; ++n) {
  1086. i >>= 1;
  1087. }
  1088. return n;
  1089. #endif
  1090. }
  1091. strong_alias(__ffs, ffs)
  1092. #endif
  1093. /**********************************************************************/
  1094. #if defined(L_strcasecmp) || defined(L_strcasecmp_l) || defined(L_wcscasecmp) || defined(L_wcscasecmp_l)
  1095. #if defined(L_wcscasecmp) || defined(L_wcscasecmp_l)
  1096. #define strcasecmp wcscasecmp
  1097. #define strcasecmp_l wcscasecmp_l
  1098. #define __strcasecmp_l __wcscasecmp_l
  1099. #ifdef __UCLIBC_DO_XLOCALE
  1100. #define TOLOWER(C) __towlower_l((C), locale_arg)
  1101. #else
  1102. #define TOLOWER(C) towlower((C))
  1103. #endif
  1104. #else /* defined(L_wcscasecmp) || defined(L_wcscasecmp_l) */
  1105. #ifdef __UCLIBC_DO_XLOCALE
  1106. #define TOLOWER(C) __tolower_l((C), locale_arg)
  1107. #else
  1108. #define TOLOWER(C) tolower((C))
  1109. #endif
  1110. #endif /* defined(L_wcscasecmp) || defined(L_wcscasecmp_l) */
  1111. #if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
  1112. int strcasecmp(register const Wchar *s1, register const Wchar *s2)
  1113. {
  1114. return __strcasecmp_l(s1, s2, __UCLIBC_CURLOCALE);
  1115. }
  1116. #else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  1117. int __XL(strcasecmp)(register const Wchar *s1, register const Wchar *s2
  1118. __LOCALE_PARAM )
  1119. {
  1120. #ifdef WANT_WIDE
  1121. while ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2))) {
  1122. if (!*s1++) {
  1123. return 0;
  1124. }
  1125. ++s2;
  1126. }
  1127. return (((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1;
  1128. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  1129. #else
  1130. int r = 0;
  1131. while ( ((s1 == s2) ||
  1132. !(r = ((int)( TOLOWER(*((Wuchar *)s1))))
  1133. - TOLOWER(*((Wuchar *)s2))))
  1134. && (++s2, *s1++));
  1135. return r;
  1136. #endif
  1137. }
  1138. __XL_ALIAS(strcasecmp)
  1139. #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  1140. #endif
  1141. /**********************************************************************/
  1142. #if defined(L_strncasecmp) || defined(L_strncasecmp_l) || defined(L_wcsncasecmp) || defined(L_wcsncasecmp_l)
  1143. #if defined(L_wcsncasecmp) || defined(L_wcsncasecmp_l)
  1144. #define strncasecmp wcsncasecmp
  1145. #define strncasecmp_l wcsncasecmp_l
  1146. #define __strncasecmp_l __wcsncasecmp_l
  1147. #ifdef __UCLIBC_DO_XLOCALE
  1148. #define TOLOWER(C) __towlower_l((C), locale_arg)
  1149. #else
  1150. #define TOLOWER(C) towlower((C))
  1151. #endif
  1152. #else /* defined(L_wcsncasecmp) || defined(L_wcsncasecmp_l) */
  1153. #ifdef __UCLIBC_DO_XLOCALE
  1154. #define TOLOWER(C) __tolower_l((C), locale_arg)
  1155. #else
  1156. #define TOLOWER(C) tolower((C))
  1157. #endif
  1158. #endif /* defined(L_wcsncasecmp) || defined(L_wcsncasecmp_l) */
  1159. #if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
  1160. int strncasecmp(register const Wchar *s1, register const Wchar *s2, size_t n)
  1161. {
  1162. return __strncasecmp_l(s1, s2, n, __UCLIBC_CURLOCALE);
  1163. }
  1164. #else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  1165. int __XL(strncasecmp)(register const Wchar *s1, register const Wchar *s2,
  1166. size_t n __LOCALE_PARAM )
  1167. {
  1168. #ifdef WANT_WIDE
  1169. while (n && ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2)))) {
  1170. if (!*s1++) {
  1171. return 0;
  1172. }
  1173. ++s2;
  1174. --n;
  1175. }
  1176. return (n == 0)
  1177. ? 0
  1178. : ((((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1);
  1179. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  1180. #else
  1181. int r = 0;
  1182. while ( n
  1183. && ((s1 == s2) ||
  1184. !(r = ((int)( TOLOWER(*((unsigned char *)s1))))
  1185. - TOLOWER(*((unsigned char *)s2))))
  1186. && (--n, ++s2, *s1++));
  1187. return r;
  1188. #endif
  1189. }
  1190. __XL_ALIAS(strncasecmp)
  1191. #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  1192. #endif
  1193. /**********************************************************************/
  1194. #if 0
  1195. #ifdef L_wcsnlen
  1196. #define L_strnlen
  1197. #define Wstrnlen wcsnlen
  1198. #else
  1199. #define Wstrnlen strnlen
  1200. #endif
  1201. #endif
  1202. #ifdef L_strnlen
  1203. #ifndef WANT_WIDE
  1204. #undef strnlen
  1205. #else
  1206. #undef wcsnlen
  1207. #endif
  1208. size_t attribute_hidden Wstrnlen(const Wchar *s, size_t max)
  1209. {
  1210. register const Wchar *p = s;
  1211. #ifdef __BCC__
  1212. /* bcc can optimize the counter if it thinks it is a pointer... */
  1213. register const char *maxp = (const char *) max;
  1214. #else
  1215. #define maxp max
  1216. #endif
  1217. while (maxp && *p) {
  1218. ++p;
  1219. --maxp;
  1220. }
  1221. return p - s;
  1222. }
  1223. #undef maxp
  1224. #endif
  1225. /**********************************************************************/
  1226. /* No wide analog. */
  1227. #ifdef L_memccpy
  1228. #undef memccpy
  1229. void attribute_hidden *__memccpy(void * __restrict s1, const void * __restrict s2, int c, size_t n)
  1230. {
  1231. register char *r1 = s1;
  1232. register const char *r2 = s2;
  1233. while (n-- && (((unsigned char)(*r1++ = *r2++)) != ((unsigned char) c)));
  1234. return (n == (size_t) -1) ? NULL : r1;
  1235. }
  1236. strong_alias(__memccpy, memccpy)
  1237. #endif
  1238. /**********************************************************************/
  1239. #if 0
  1240. #undef Wstrlen
  1241. #undef Wstrcpy
  1242. #ifdef L_wcsdup
  1243. #define L_strdup
  1244. #define Wstrdup wcsdup
  1245. #define Wstrlen wcslen
  1246. #define Wstrcpy wcscpy
  1247. #else
  1248. #define Wstrdup strdup
  1249. #define Wstrlen strlen
  1250. #define Wstrcpy strcpy
  1251. #endif
  1252. #endif
  1253. #ifdef L_strdup
  1254. #ifndef WANT_WIDE
  1255. #undef strdup
  1256. #else
  1257. #undef wcsdup
  1258. #endif
  1259. Wchar attribute_hidden *Wstrdup(register const Wchar *s1)
  1260. {
  1261. register Wchar *s;
  1262. if ((s = malloc((Wstrlen(s1) + 1) * sizeof(Wchar))) != NULL) {
  1263. Wstrcpy(s, s1);
  1264. }
  1265. return s;
  1266. }
  1267. #endif
  1268. /**********************************************************************/
  1269. #ifdef L_strerror
  1270. #undef strerror
  1271. char attribute_hidden *__strerror(int errnum)
  1272. {
  1273. static char buf[_STRERROR_BUFSIZE];
  1274. __xpg_strerror_r(errnum, buf, sizeof(buf));
  1275. return buf;
  1276. }
  1277. strong_alias(__strerror, strerror)
  1278. #endif
  1279. /**********************************************************************/
  1280. /* SUSv3 functions. */
  1281. /**********************************************************************/
  1282. #ifdef L___xpg_strerror_r
  1283. #ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
  1284. #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
  1285. static const unsigned char estridx[] = {
  1286. 0, /* success is always 0 */
  1287. EPERM,
  1288. ENOENT,
  1289. ESRCH,
  1290. EINTR,
  1291. EIO,
  1292. ENXIO,
  1293. E2BIG,
  1294. ENOEXEC,
  1295. EBADF,
  1296. ECHILD,
  1297. EAGAIN,
  1298. ENOMEM,
  1299. EACCES,
  1300. EFAULT,
  1301. ENOTBLK,
  1302. EBUSY,
  1303. EEXIST,
  1304. EXDEV,
  1305. ENODEV,
  1306. ENOTDIR,
  1307. EISDIR,
  1308. EINVAL,
  1309. ENFILE,
  1310. EMFILE,
  1311. ENOTTY,
  1312. ETXTBSY,
  1313. EFBIG,
  1314. ENOSPC,
  1315. ESPIPE,
  1316. EROFS,
  1317. EMLINK,
  1318. EPIPE,
  1319. EDOM,
  1320. ERANGE,
  1321. EDEADLK,
  1322. ENAMETOOLONG,
  1323. ENOLCK,
  1324. ENOSYS,
  1325. ENOTEMPTY,
  1326. ELOOP,
  1327. 0,
  1328. ENOMSG,
  1329. EIDRM,
  1330. ECHRNG,
  1331. EL2NSYNC,
  1332. EL3HLT,
  1333. EL3RST,
  1334. ELNRNG,
  1335. EUNATCH,
  1336. ENOCSI,
  1337. EL2HLT,
  1338. EBADE,
  1339. EBADR,
  1340. EXFULL,
  1341. ENOANO,
  1342. EBADRQC,
  1343. EBADSLT,
  1344. 0,
  1345. EBFONT,
  1346. ENOSTR,
  1347. ENODATA,
  1348. ETIME,
  1349. ENOSR,
  1350. ENONET,
  1351. ENOPKG,
  1352. EREMOTE,
  1353. ENOLINK,
  1354. EADV,
  1355. ESRMNT,
  1356. ECOMM,
  1357. EPROTO,
  1358. EMULTIHOP,
  1359. EDOTDOT,
  1360. EBADMSG,
  1361. EOVERFLOW,
  1362. ENOTUNIQ,
  1363. EBADFD,
  1364. EREMCHG,
  1365. ELIBACC,
  1366. ELIBBAD,
  1367. ELIBSCN,
  1368. ELIBMAX,
  1369. ELIBEXEC,
  1370. EILSEQ,
  1371. ERESTART,
  1372. ESTRPIPE,
  1373. EUSERS,
  1374. ENOTSOCK,
  1375. EDESTADDRREQ,
  1376. EMSGSIZE,
  1377. EPROTOTYPE,
  1378. ENOPROTOOPT,
  1379. EPROTONOSUPPORT,
  1380. ESOCKTNOSUPPORT,
  1381. EOPNOTSUPP,
  1382. EPFNOSUPPORT,
  1383. EAFNOSUPPORT,
  1384. EADDRINUSE,
  1385. EADDRNOTAVAIL,
  1386. ENETDOWN,
  1387. ENETUNREACH,
  1388. ENETRESET,
  1389. ECONNABORTED,
  1390. ECONNRESET,
  1391. ENOBUFS,
  1392. EISCONN,
  1393. ENOTCONN,
  1394. ESHUTDOWN,
  1395. ETOOMANYREFS,
  1396. ETIMEDOUT,
  1397. ECONNREFUSED,
  1398. EHOSTDOWN,
  1399. EHOSTUNREACH,
  1400. EALREADY,
  1401. EINPROGRESS,
  1402. ESTALE,
  1403. EUCLEAN,
  1404. ENOTNAM,
  1405. ENAVAIL,
  1406. EISNAM,
  1407. EREMOTEIO,
  1408. #ifdef __mips__
  1409. 0, /* mips has an outrageous value for this... */
  1410. #else
  1411. EDQUOT,
  1412. #endif
  1413. ENOMEDIUM,
  1414. EMEDIUMTYPE,
  1415. #if defined(__mips__) || defined(__sparc__)
  1416. EDEADLOCK,
  1417. #endif
  1418. };
  1419. #endif
  1420. int __xpg_strerror_r(int errnum, char *strerrbuf, size_t buflen)
  1421. {
  1422. register char *s;
  1423. int i, retval;
  1424. char buf[_STRERROR_BUFSIZE];
  1425. static const char unknown[] = {
  1426. 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
  1427. };
  1428. retval = EINVAL;
  1429. #ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
  1430. #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
  1431. /* Need to translate errno to string index. */
  1432. for (i = 0 ; i < sizeof(estridx)/sizeof(estridx[0]) ; i++) {
  1433. if (estridx[i] == errnum) {
  1434. goto GOT_ESTRIDX;
  1435. }
  1436. }
  1437. i = INT_MAX; /* Failed, but may need to check mips special case. */
  1438. #ifdef __mips__
  1439. if (errnum == EDQUOT) { /* Deal with large EDQUOT value on mips */
  1440. i = 122;
  1441. }
  1442. #endif /* __mips__ */
  1443. GOT_ESTRIDX:
  1444. #else
  1445. /* No errno to string index translation needed. */
  1446. i = errnum;
  1447. #endif
  1448. if (((unsigned int) i) < _SYS_NERR) {
  1449. /* Trade time for space. This function should rarely be called
  1450. * so rather than keeping an array of pointers for the different
  1451. * messages, just run through the buffer until we find the
  1452. * correct string. */
  1453. for (s = (char *) _string_syserrmsgs ; i ; ++s) {
  1454. if (!*s) {
  1455. --i;
  1456. }
  1457. }
  1458. if (*s) { /* Make sure we have an actual message. */
  1459. retval = 0;
  1460. goto GOT_MESG;
  1461. }
  1462. }
  1463. #endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
  1464. s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
  1465. __memcpy(s, unknown, sizeof(unknown));
  1466. GOT_MESG:
  1467. if (!strerrbuf) { /* SUSv3 */
  1468. buflen = 0;
  1469. }
  1470. i = strlen(s) + 1;
  1471. if (i > buflen) {
  1472. i = buflen;
  1473. retval = ERANGE;
  1474. }
  1475. if (i) {
  1476. __memcpy(strerrbuf, s, i);
  1477. strerrbuf[i-1] = 0; /* In case buf was too small. */
  1478. }
  1479. if (retval) {
  1480. __set_errno(retval);
  1481. }
  1482. return retval;
  1483. }
  1484. #else /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
  1485. int __xpg_strerror_r(int errnum, char *strerrbuf, size_t buflen)
  1486. {
  1487. register char *s;
  1488. int i, retval;
  1489. char buf[_STRERROR_BUFSIZE];
  1490. static const char unknown[] = {
  1491. 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
  1492. };
  1493. s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
  1494. __memcpy(s, unknown, sizeof(unknown));
  1495. if (!strerrbuf) { /* SUSv3 */
  1496. buflen = 0;
  1497. }
  1498. retval = EINVAL;
  1499. i = buf + sizeof(buf) - s;
  1500. if (i > buflen) {
  1501. i = buflen;
  1502. retval = ERANGE;
  1503. }
  1504. if (i) {
  1505. __memcpy(strerrbuf, s, i);
  1506. strerrbuf[i-1] = 0; /* In case buf was too small. */
  1507. }
  1508. __set_errno(retval);
  1509. return retval;
  1510. }
  1511. #endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
  1512. #endif
  1513. /**********************************************************************/
  1514. /* GNU extension functions. */
  1515. /**********************************************************************/
  1516. #ifdef L___glibc_strerror_r
  1517. char *__glibc_strerror_r(int errnum, char *strerrbuf, size_t buflen)
  1518. {
  1519. __xpg_strerror_r(errnum, strerrbuf, buflen);
  1520. return strerrbuf;
  1521. }
  1522. weak_alias(__glibc_strerror_r, __strerror_r)
  1523. #endif
  1524. /**********************************************************************/
  1525. #ifdef L_memmem
  1526. #undef memmem
  1527. void attribute_hidden *__memmem(const void *haystack, size_t haystacklen,
  1528. const void *needle, size_t needlelen)
  1529. {
  1530. register const char *ph;
  1531. register const char *pn;
  1532. const char *plast;
  1533. size_t n;
  1534. if (needlelen == 0) {
  1535. return (void *) haystack;
  1536. }
  1537. if (haystacklen >= needlelen) {
  1538. ph = (const char *) haystack;
  1539. pn = (const char *) needle;
  1540. plast = ph + (haystacklen - needlelen);
  1541. do {
  1542. n = 0;
  1543. while (ph[n] == pn[n]) {
  1544. if (++n == needlelen) {
  1545. return (void *) ph;
  1546. }
  1547. }
  1548. } while (++ph <= plast);
  1549. }
  1550. return NULL;
  1551. }
  1552. strong_alias(__memmem, memmem)
  1553. #endif
  1554. /**********************************************************************/
  1555. #if 0
  1556. #ifdef L_wmempcpy
  1557. #define L_mempcpy
  1558. #define Wmempcpy wmempcpy
  1559. #else
  1560. #define Wmempcpy __mempcpy
  1561. #endif
  1562. #endif
  1563. #ifdef L_mempcpy
  1564. #ifndef WANT_WIDE
  1565. #undef mempcpy
  1566. #else
  1567. #undef wmempcpy
  1568. #endif
  1569. Wvoid attribute_hidden *Wmempcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
  1570. {
  1571. register Wchar *r1 = s1;
  1572. register const Wchar *r2 = s2;
  1573. #ifdef __BCC__
  1574. while (n--) {
  1575. *r1++ = *r2++;
  1576. }
  1577. #else
  1578. while (n) {
  1579. *r1++ = *r2++;
  1580. --n;
  1581. }
  1582. #endif
  1583. return r1;
  1584. }
  1585. #if 0 /* ndef L_wmempcpy */
  1586. weak_alias(__mempcpy, mempcpy)
  1587. #endif
  1588. #endif
  1589. /**********************************************************************/
  1590. #ifdef L_memrchr
  1591. #undef memrchr
  1592. void attribute_hidden *__memrchr(const void *s, int c, size_t n)
  1593. {
  1594. register const unsigned char *r;
  1595. #ifdef __BCC__
  1596. /* bcc can optimize the counter if it thinks it is a pointer... */
  1597. register const char *np = (const char *) n;
  1598. #else
  1599. #define np n
  1600. #endif
  1601. r = ((unsigned char *)s) + ((size_t) np);
  1602. while (np) {
  1603. if (*--r == ((unsigned char)c)) {
  1604. return (void *) r; /* silence the warning */
  1605. }
  1606. --np;
  1607. }
  1608. return NULL;
  1609. }
  1610. #undef np
  1611. strong_alias(__memrchr, memrchr)
  1612. #endif
  1613. /**********************************************************************/
  1614. #if 0
  1615. #ifdef L_wcpcpy
  1616. #define L_stpcpy
  1617. #define Wstpcpy wcpcpy
  1618. #else
  1619. #define Wstpcpy stpcpy
  1620. #endif
  1621. #endif
  1622. #ifdef L_stpcpy
  1623. #ifndef WANT_WIDE
  1624. #undef stpcpy
  1625. #else
  1626. #undef wcpcpy
  1627. #endif
  1628. Wchar attribute_hidden *Wstpcpy(register Wchar * __restrict s1, const Wchar * __restrict s2)
  1629. {
  1630. #ifdef __BCC__
  1631. do {
  1632. *s1 = *s2++;
  1633. } while (*s1++ != 0);
  1634. #else
  1635. while ( (*s1++ = *s2++) != 0 );
  1636. #endif
  1637. return s1 - 1;
  1638. }
  1639. #endif
  1640. /**********************************************************************/
  1641. #if 0
  1642. #ifdef L_wcpncpy
  1643. #define L_stpncpy
  1644. #define Wstpncpy wcpncpy
  1645. #else
  1646. #define Wstpncpy stpncpy
  1647. #endif
  1648. #endif
  1649. #ifdef L_stpncpy
  1650. #ifndef WANT_WIDE
  1651. #undef stpncpy
  1652. #else
  1653. #undef wcpncpy
  1654. #endif
  1655. Wchar attribute_hidden *Wstpncpy(register Wchar * __restrict s1,
  1656. register const Wchar * __restrict s2,
  1657. size_t n)
  1658. {
  1659. Wchar *s = s1;
  1660. const Wchar *p = s2;
  1661. #ifdef __BCC__
  1662. while (n--) {
  1663. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  1664. ++s;
  1665. }
  1666. return s1 + (s2 - p);
  1667. #else
  1668. while (n) {
  1669. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  1670. ++s;
  1671. --n;
  1672. }
  1673. return s1 + (s2 - p);
  1674. #endif
  1675. }
  1676. #endif
  1677. /**********************************************************************/
  1678. #ifdef L_bzero
  1679. #undef bzero
  1680. void attribute_hidden __bzero(void *s, size_t n)
  1681. {
  1682. #if 1
  1683. (void)__memset(s, 0, n);
  1684. #else
  1685. register unsigned char *p = s;
  1686. #ifdef __BCC__
  1687. /* bcc can optimize the counter if it thinks it is a pointer... */
  1688. register const char *np = (const char *) n;
  1689. #else
  1690. #define np n
  1691. #endif
  1692. while (np) {
  1693. *p++ = 0;
  1694. --np;
  1695. }
  1696. #endif
  1697. }
  1698. #if 0
  1699. weak_alias(__bzero, bzero)
  1700. #else
  1701. strong_alias(__bzero, bzero)
  1702. #endif
  1703. #undef np
  1704. #endif
  1705. /**********************************************************************/
  1706. #ifdef L_bcopy
  1707. #undef bcopy
  1708. void attribute_hidden __bcopy(const void *s2, void *s1, size_t n)
  1709. {
  1710. #if 1
  1711. __memmove(s1, s2, n);
  1712. #else
  1713. #ifdef __BCC__
  1714. register char *s;
  1715. register const char *p;
  1716. s = s1;
  1717. p = s2;
  1718. if (p >= s) {
  1719. while (n--) {
  1720. *s++ = *p++;
  1721. }
  1722. } else {
  1723. s += n;
  1724. p += n;
  1725. while (n--) {
  1726. *--s = *--p;
  1727. }
  1728. }
  1729. #else
  1730. register char *s;
  1731. register const char *p;
  1732. s = s1;
  1733. p = s2;
  1734. if (p >= s) {
  1735. while (n) {
  1736. *s++ = *p++;
  1737. --n;
  1738. }
  1739. } else {
  1740. while (n) {
  1741. --n;
  1742. s[n] = p[n];
  1743. }
  1744. }
  1745. #endif
  1746. #endif
  1747. }
  1748. strong_alias(__bcopy, bcopy)
  1749. #endif
  1750. /**********************************************************************/
  1751. #ifdef L_strcasestr
  1752. #undef strcasestr
  1753. char attribute_hidden *__strcasestr(const char *s1, const char *s2)
  1754. {
  1755. register const char *s = s1;
  1756. register const char *p = s2;
  1757. #if 1
  1758. do {
  1759. if (!*p) {
  1760. return (char *) s1;;
  1761. }
  1762. if ((*p == *s)
  1763. || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
  1764. ) {
  1765. ++p;
  1766. ++s;
  1767. } else {
  1768. p = s2;
  1769. if (!*s) {
  1770. return NULL;
  1771. }
  1772. s = ++s1;
  1773. }
  1774. } while (1);
  1775. #else
  1776. while (*p && *s) {
  1777. if ((*p == *s)
  1778. || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
  1779. ) {
  1780. ++p;
  1781. ++s;
  1782. } else {
  1783. p = s2;
  1784. s = ++s1;
  1785. }
  1786. }
  1787. return (*p) ? NULL : (char *) s1;
  1788. #endif
  1789. }
  1790. strong_alias(__strcasestr, strcasestr)
  1791. #endif
  1792. /**********************************************************************/
  1793. #ifdef L_strndup
  1794. #undef strndup
  1795. char attribute_hidden *__strndup(register const char *s1, size_t n)
  1796. {
  1797. register char *s;
  1798. n = __strnlen(s1,n); /* Avoid problems if s1 not nul-terminated. */
  1799. if ((s = malloc(n + 1)) != NULL) {
  1800. __memcpy(s, s1, n);
  1801. s[n] = 0;
  1802. }
  1803. return s;
  1804. }
  1805. strong_alias(__strndup, strndup)
  1806. #endif
  1807. /**********************************************************************/
  1808. #ifdef L_strsep
  1809. #undef strsep
  1810. char attribute_hidden *__strsep(char ** __restrict s1, const char * __restrict s2)
  1811. {
  1812. register char *s = *s1;
  1813. register char *p;
  1814. #if 1
  1815. p = NULL;
  1816. if (s && *s && (p = __strpbrk(s, s2))) {
  1817. *p++ = 0;
  1818. }
  1819. #else
  1820. if (s && *s && *(p = s + strcspn(s, s2))) {
  1821. *p++ = 0;
  1822. } else {
  1823. p = NULL;
  1824. }
  1825. #endif
  1826. *s1 = p;
  1827. return s;
  1828. }
  1829. strong_alias(__strsep, strsep)
  1830. #endif
  1831. /**********************************************************************/
  1832. #if 0
  1833. #ifdef L_wcschrnul
  1834. #define L_strchrnul
  1835. #define __Wstrchrnul __wcschrnul
  1836. #define Wstrchrnul wcschrnul
  1837. #else
  1838. #define __Wstrchrnul __strchrnul
  1839. #define Wstrchrnul strchrnul
  1840. #endif
  1841. #endif
  1842. #ifdef L_strchrnul
  1843. #ifndef WANT_WIDE
  1844. #undef strchrnul
  1845. #else
  1846. #undef wcschrnul
  1847. #endif
  1848. Wchar attribute_hidden *Wstrchrnul(register const Wchar *s, Wint c)
  1849. {
  1850. --s;
  1851. while (*++s && (*s != ((Wchar)c)));
  1852. return (Wchar *) s;
  1853. }
  1854. #if 0
  1855. weak_alias(__Wstrchrnul, Wstrchrnul)
  1856. #endif
  1857. #endif
  1858. /**********************************************************************/
  1859. #ifdef L_rawmemchr
  1860. #undef rawmemchr
  1861. void attribute_hidden *__rawmemchr(const void *s, int c)
  1862. {
  1863. register const unsigned char *r = s;
  1864. while (*r != ((unsigned char)c)) ++r;
  1865. return (void *) r; /* silence the warning */
  1866. }
  1867. strong_alias(__rawmemchr, rawmemchr)
  1868. #endif
  1869. /**********************************************************************/
  1870. #ifdef L_basename
  1871. #undef basename
  1872. char attribute_hidden *__basename(const char *path)
  1873. {
  1874. register const char *s;
  1875. register const char *p;
  1876. p = s = path;
  1877. while (*s) {
  1878. if (*s++ == '/') {
  1879. p = s;
  1880. }
  1881. }
  1882. return (char *) p;
  1883. }
  1884. strong_alias(__basename, basename)
  1885. #endif
  1886. /**********************************************************************/
  1887. #ifdef L___xpg_basename
  1888. char *__xpg_basename(register char *path)
  1889. {
  1890. static const char null_or_empty[] = ".";
  1891. char *first;
  1892. register char *last;
  1893. first = (char *) null_or_empty;
  1894. if (path && *path) {
  1895. first = path;
  1896. last = path - 1;
  1897. do {
  1898. if ((*path != '/') && (path > ++last)) {
  1899. last = first = path;
  1900. }
  1901. } while (*++path);
  1902. if (*first == '/') {
  1903. last = first;
  1904. }
  1905. last[1] = 0;
  1906. }
  1907. return first;
  1908. }
  1909. #endif
  1910. /**********************************************************************/
  1911. #ifdef L_dirname
  1912. char *dirname(char *path)
  1913. {
  1914. static const char null_or_empty_or_noslash[] = ".";
  1915. register char *s;
  1916. register char *last;
  1917. char *first;
  1918. last = s = path;
  1919. if (s != NULL) {
  1920. LOOP:
  1921. while (*s && (*s != '/')) ++s;
  1922. first = s;
  1923. while (*s == '/') ++s;
  1924. if (*s) {
  1925. last = first;
  1926. goto LOOP;
  1927. }
  1928. if (last == path) {
  1929. if (*last != '/') {
  1930. goto DOT;
  1931. }
  1932. if ((*++last == '/') && (last[1] == 0)) {
  1933. ++last;
  1934. }
  1935. }
  1936. *last = 0;
  1937. return path;
  1938. }
  1939. DOT:
  1940. return (char *) null_or_empty_or_noslash;
  1941. }
  1942. #endif
  1943. /**********************************************************************/
  1944. #ifdef L_strlcat
  1945. /* OpenBSD function:
  1946. * Append at most n-1-strlen(dst) chars from src to dst and nul-terminate dst.
  1947. * Returns strlen(src) + strlen({original} dst), so truncation occurred if the
  1948. * return val is >= n.
  1949. * Note: If dst doesn't contain a nul in the first n chars, strlen(dst) is
  1950. * taken as n. */
  1951. size_t strlcat(register char *__restrict dst,
  1952. register const char *__restrict src,
  1953. size_t n)
  1954. {
  1955. size_t len;
  1956. char dummy[1];
  1957. len = 0;
  1958. while (1) {
  1959. if (len >= n) {
  1960. dst = dummy;
  1961. break;
  1962. }
  1963. if (!*dst) {
  1964. break;
  1965. }
  1966. ++dst;
  1967. ++len;
  1968. }
  1969. while ((*dst = *src) != 0) {
  1970. if (++len < n) {
  1971. ++dst;
  1972. }
  1973. ++src;
  1974. }
  1975. return len;
  1976. }
  1977. #endif
  1978. /**********************************************************************/
  1979. #if 0
  1980. #ifdef WANT_WIDE
  1981. extern size_t __wcslcpy(wchar_t *__restrict dst,
  1982. const wchar_t *__restrict src,
  1983. size_t n);
  1984. #endif
  1985. #ifdef L___wcslcpy
  1986. #define L_strlcpy
  1987. #define Wstrlcpy __wcslcpy
  1988. #else
  1989. #define Wstrlcpy strlcpy
  1990. #endif
  1991. #endif
  1992. #ifdef L_strlcpy
  1993. /* OpenBSD function:
  1994. * Copy at most n-1 chars from src to dst and nul-terminate dst.
  1995. * Returns strlen(src), so truncation occurred if the return value is >= n. */
  1996. #ifndef WANT_WIDE
  1997. #undef strlcpy
  1998. #else
  1999. #undef wcslcpy
  2000. #endif
  2001. size_t attribute_hidden Wstrlcpy(register Wchar *__restrict dst,
  2002. register const Wchar *__restrict src,
  2003. size_t n)
  2004. {
  2005. const Wchar *src0 = src;
  2006. Wchar dummy[1];
  2007. if (!n) {
  2008. dst = dummy;
  2009. } else {
  2010. --n;
  2011. }
  2012. while ((*dst = *src) != 0) {
  2013. if (n) {
  2014. --n;
  2015. ++dst;
  2016. }
  2017. ++src;
  2018. }
  2019. return src - src0;
  2020. }
  2021. #if 0 /* def __LOCALE_C_ONLY */
  2022. #ifdef L___wcslcpy
  2023. weak_alias(__wcslcpy,wcsxfrm);
  2024. #else
  2025. weak_alias(strlcpy,strxfrm);
  2026. #endif
  2027. #endif
  2028. #endif
  2029. /**********************************************************************/
  2030. #if defined(L__string_syssigmsgs) && defined(__UCLIBC_HAS_SIGNUM_MESSAGES__)
  2031. const char _string_syssigmsgs[] = {
  2032. /* 0: 0, 1 */ "\0"
  2033. /* 1: 1, 7 */ "Hangup\0"
  2034. /* 2: 8, 10 */ "Interrupt\0"
  2035. /* 3: 18, 5 */ "Quit\0"
  2036. /* 4: 23, 20 */ "Illegal instruction\0"
  2037. /* 5: 43, 22 */ "Trace/breakpoint trap\0"
  2038. /* 6: 65, 8 */ "Aborted\0"
  2039. /* 7: 73, 10 */ "Bus error\0"
  2040. /* 8: 83, 25 */ "Floating point exception\0"
  2041. /* 9: 108, 7 */ "Killed\0"
  2042. /* 10: 115, 22 */ "User defined signal 1\0"
  2043. /* 11: 137, 19 */ "Segmentation fault\0"
  2044. /* 12: 156, 22 */ "User defined signal 2\0"
  2045. /* 13: 178, 12 */ "Broken pipe\0"
  2046. /* 14: 190, 12 */ "Alarm clock\0"
  2047. /* 15: 202, 11 */ "Terminated\0"
  2048. /* 16: 213, 12 */ "Stack fault\0"
  2049. /* 17: 225, 13 */ "Child exited\0"
  2050. /* 18: 238, 10 */ "Continued\0"
  2051. /* 19: 248, 17 */ "Stopped (signal)\0"
  2052. /* 20: 265, 8 */ "Stopped\0"
  2053. /* 21: 273, 20 */ "Stopped (tty input)\0"
  2054. /* 22: 293, 21 */ "Stopped (tty output)\0"
  2055. /* 23: 314, 21 */ "Urgent I/O condition\0"
  2056. /* 24: 335, 24 */ "CPU time limit exceeded\0"
  2057. /* 25: 359, 25 */ "File size limit exceeded\0"
  2058. /* 26: 384, 22 */ "Virtual timer expired\0"
  2059. /* 27: 406, 24 */ "Profiling timer expired\0"
  2060. /* 28: 430, 15 */ "Window changed\0"
  2061. /* 29: 445, 13 */ "I/O possible\0"
  2062. /* 30: 458, 14 */ "Power failure\0"
  2063. /* 31: 472, 16 */ "Bad system call"
  2064. #if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
  2065. /* 32: 488, 9 */ "\0EMT trap"
  2066. #endif
  2067. };
  2068. #endif
  2069. /**********************************************************************/
  2070. #if defined(L_sys_siglist) && defined(__UCLIBC_HAS_SYS_SIGLIST__)
  2071. const char *const sys_siglist[_NSIG] = {
  2072. [0] = NULL,
  2073. [SIGHUP] = _string_syssigmsgs + 1,
  2074. [SIGINT] = _string_syssigmsgs + 8,
  2075. [SIGQUIT] = _string_syssigmsgs + 18,
  2076. [SIGILL] = _string_syssigmsgs + 23,
  2077. [SIGTRAP] = _string_syssigmsgs + 43,
  2078. [SIGABRT] = _string_syssigmsgs + 65,
  2079. [SIGBUS] = _string_syssigmsgs + 73,
  2080. [SIGFPE] = _string_syssigmsgs + 83,
  2081. [SIGKILL] = _string_syssigmsgs + 108,
  2082. [SIGUSR1] = _string_syssigmsgs + 115,
  2083. [SIGSEGV] = _string_syssigmsgs + 137,
  2084. [SIGUSR2] = _string_syssigmsgs + 156,
  2085. [SIGPIPE] = _string_syssigmsgs + 178,
  2086. [SIGALRM] = _string_syssigmsgs + 190,
  2087. [SIGTERM] = _string_syssigmsgs + 202,
  2088. #if !(defined(__alpha__) || defined(__mips__) || defined(__sparc__))
  2089. [SIGSTKFLT] = _string_syssigmsgs + 213,
  2090. #endif
  2091. [SIGCHLD] = _string_syssigmsgs + 225,
  2092. [SIGCONT] = _string_syssigmsgs + 238,
  2093. [SIGSTOP] = _string_syssigmsgs + 248,
  2094. [SIGTSTP] = _string_syssigmsgs + 265,
  2095. [SIGTTIN] = _string_syssigmsgs + 273,
  2096. [SIGTTOU] = _string_syssigmsgs + 293,
  2097. [SIGURG] = _string_syssigmsgs + 314,
  2098. [SIGXCPU] = _string_syssigmsgs + 335,
  2099. [SIGXFSZ] = _string_syssigmsgs + 359,
  2100. [SIGVTALRM] = _string_syssigmsgs + 384,
  2101. [SIGPROF] = _string_syssigmsgs + 406,
  2102. [SIGWINCH] = _string_syssigmsgs + 430,
  2103. [SIGIO] = _string_syssigmsgs + 445,
  2104. [SIGPWR] = _string_syssigmsgs + 458,
  2105. [SIGSYS] = _string_syssigmsgs + 472,
  2106. #if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
  2107. [SIGEMT] = _string_syssigmsgs + 488,
  2108. #endif
  2109. };
  2110. #endif
  2111. /**********************************************************************/
  2112. #ifdef L_strsignal
  2113. /* TODO: make a threadsafe version? */
  2114. #undef strsignal
  2115. #ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
  2116. #if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
  2117. static const unsigned char sstridx[] = {
  2118. 0,
  2119. SIGHUP,
  2120. SIGINT,
  2121. SIGQUIT,
  2122. SIGILL,
  2123. SIGTRAP,
  2124. SIGIOT,
  2125. SIGBUS,
  2126. SIGFPE,
  2127. SIGKILL,
  2128. SIGUSR1,
  2129. SIGSEGV,
  2130. SIGUSR2,
  2131. SIGPIPE,
  2132. SIGALRM,
  2133. SIGTERM,
  2134. #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
  2135. 0,
  2136. #else
  2137. SIGSTKFLT,
  2138. #endif
  2139. SIGCHLD,
  2140. SIGCONT,
  2141. SIGSTOP,
  2142. SIGTSTP,
  2143. SIGTTIN,
  2144. SIGTTOU,
  2145. SIGURG,
  2146. SIGXCPU,
  2147. SIGXFSZ,
  2148. SIGVTALRM,
  2149. SIGPROF,
  2150. SIGWINCH,
  2151. SIGIO,
  2152. SIGPWR,
  2153. SIGSYS,
  2154. #if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
  2155. SIGEMT,
  2156. #endif
  2157. };
  2158. #endif
  2159. char attribute_hidden *__strsignal(int signum)
  2160. {
  2161. register char *s;
  2162. int i;
  2163. static char buf[_STRSIGNAL_BUFSIZE];
  2164. static const char unknown[] = {
  2165. 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' '
  2166. };
  2167. #if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
  2168. /* Need to translate signum to string index. */
  2169. for (i = 0 ; i < sizeof(sstridx)/sizeof(sstridx[0]) ; i++) {
  2170. if (sstridx[i] == signum) {
  2171. goto GOT_SSTRIDX;
  2172. }
  2173. }
  2174. i = INT_MAX; /* Failed. */
  2175. GOT_SSTRIDX:
  2176. #else
  2177. /* No signum to string index translation needed. */
  2178. i = signum;
  2179. #endif
  2180. if (((unsigned int) signum) < _SYS_NSIG) {
  2181. /* Trade time for space. This function should rarely be called
  2182. * so rather than keeping an array of pointers for the different
  2183. * messages, just run through the buffer until we find the
  2184. * correct string. */
  2185. for (s = (char *) _string_syssigmsgs ; i ; ++s) {
  2186. if (!*s) {
  2187. --i;
  2188. }
  2189. }
  2190. if (*s) { /* Make sure we have an actual message. */
  2191. goto DONE;
  2192. }
  2193. }
  2194. s = _int10tostr(buf+sizeof(buf)-1, signum) - sizeof(unknown);
  2195. __memcpy(s, unknown, sizeof(unknown));
  2196. DONE:
  2197. return s;
  2198. }
  2199. #else /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
  2200. char attribute_hidden *__strsignal(int signum)
  2201. {
  2202. static char buf[_STRSIGNAL_BUFSIZE];
  2203. static const char unknown[] = {
  2204. 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' '
  2205. };
  2206. return (char *) __memcpy(_int10tostr(buf+sizeof(buf)-1, signum)
  2207. - sizeof(unknown),
  2208. unknown, sizeof(unknown));
  2209. }
  2210. #endif /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
  2211. strong_alias(__strsignal, strsignal)
  2212. #endif
  2213. /**********************************************************************/
  2214. #ifdef L_psignal
  2215. /* TODO: make this threadsafe with a reentrant version of strsignal? */
  2216. void psignal(int signum, register const char *message)
  2217. {
  2218. /* If the program is calling psignal, it's a safe bet that printf and
  2219. * friends are used as well. It is also possible that the calling
  2220. * program could buffer stderr, or reassign it. */
  2221. register const char *sep;
  2222. sep = ": ";
  2223. if (!(message && *message)) { /* Caller did not supply a prefix message */
  2224. message = (sep += 2); /* or passed an empty string. */
  2225. }
  2226. fprintf(stderr, "%s%s%s\n", message, sep, __strsignal(signum));
  2227. }
  2228. #endif
  2229. /**********************************************************************/
  2230. #ifndef __LOCALE_C_ONLY
  2231. #if defined(L_strxfrm) || defined(L_strxfrm_l) || defined(L_wcsxfrm) || defined(L_wcsxfrm_l)
  2232. #ifdef L_strxfrm
  2233. #ifndef WANT_WIDE
  2234. #error WANT_WIDE should be defined for L_strxfrm
  2235. #endif
  2236. #ifdef L_wcsxfrm
  2237. #error L_wcsxfrm already defined for L_strxfrm
  2238. #endif
  2239. #endif /* L_strxfrm */
  2240. #if defined(L_strxfrm) || defined(L_strxfrm_l)
  2241. #define wcscoll strcoll
  2242. #define wcscoll_l strcoll_l
  2243. #define __wcscoll_l __strcoll_l
  2244. #define wcsxfrm strxfrm
  2245. #define wcsxfrm_l strxfrm_l
  2246. #define __wcsxfrm_l __strxfrm_l
  2247. #undef WANT_WIDE
  2248. #undef Wvoid
  2249. #undef Wchar
  2250. #undef Wuchar
  2251. #undef Wint
  2252. #define Wchar char
  2253. #endif /* defined(L_strxfrm) || defined(L_strxfrm_l) */
  2254. #if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
  2255. int wcscoll (const Wchar *s0, const Wchar *s1)
  2256. {
  2257. return wcscoll_l(s0, s1, __UCLIBC_CURLOCALE );
  2258. }
  2259. size_t wcsxfrm(Wchar *__restrict ws1, const Wchar *__restrict ws2, size_t n)
  2260. {
  2261. return wcsxfrm_l(ws1, ws2, n, __UCLIBC_CURLOCALE );
  2262. }
  2263. #else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  2264. #if 0
  2265. #define CUR_COLLATE (&__UCLIBC_CURLOCALE_DATA.collate)
  2266. #else
  2267. #define CUR_COLLATE (& __LOCALE_PTR->collate)
  2268. #endif
  2269. #define MAX_PENDING 8
  2270. typedef struct {
  2271. const Wchar *s;
  2272. const Wchar *eob; /* end of backward */
  2273. __uwchar_t weight;
  2274. __uwchar_t ui_weight; /* undefined or invalid */
  2275. int colitem;
  2276. int weightidx;
  2277. int rule;
  2278. size_t position;
  2279. /* should be wchar_t. if wchar < 0 do EILSEQ? */
  2280. __uwchar_t *cip;
  2281. __uwchar_t ci_pending[MAX_PENDING]; /* nul-terminated */
  2282. char *back_buf;
  2283. char *bbe; /* end of back_buf (actual last... not 1 past end) */
  2284. char *bp; /* ptr into backbuf, NULL if not in backward mode */
  2285. char ibb[128];
  2286. size_t bb_size;
  2287. int ru_pushed;
  2288. } col_state_t;
  2289. #define WEIGHT_MASK 0x3fffU
  2290. #define RULE_MASK 0xc000U
  2291. #define RULE_FORWARD (1 << 14)
  2292. #define RULE_POSITION (1 << 15)
  2293. #define UI_IDX (WEIGHT_MASK-6)
  2294. #define POSIT_IDX (WEIGHT_MASK-5)
  2295. #define RANGE_IDX (WEIGHT_MASK-4)
  2296. #define UNDEF_IDX (WEIGHT_MASK-3)
  2297. #define INVAL_IDX (WEIGHT_MASK-2)
  2298. #define DITTO_IDX (WEIGHT_MASK-1)
  2299. #undef TRACE
  2300. #if 0
  2301. #define TRACE(X) printf X
  2302. #else
  2303. #define TRACE(X) ((void)0)
  2304. #endif
  2305. static int lookup(wchar_t wc __LOCALE_PARAM )
  2306. {
  2307. unsigned int sc, n, i0, i1;
  2308. if (((__uwchar_t) wc) > 0xffffU) {
  2309. return 0;
  2310. }
  2311. sc = wc & CUR_COLLATE->ti_mask;
  2312. wc >>= CUR_COLLATE->ti_shift;
  2313. n = wc & CUR_COLLATE->ii_mask;
  2314. wc >>= CUR_COLLATE->ii_shift;
  2315. i0 = CUR_COLLATE->wcs2colidt_tbl[wc];
  2316. i0 <<= CUR_COLLATE->ii_shift;
  2317. i1 = CUR_COLLATE->wcs2colidt_tbl[CUR_COLLATE->ii_len + i0 + n];
  2318. i1 <<= CUR_COLLATE->ti_shift;
  2319. return CUR_COLLATE->wcs2colidt_tbl[CUR_COLLATE->ii_len + CUR_COLLATE->ti_len + i1 + sc];
  2320. }
  2321. static void init_col_state(col_state_t *cs, const Wchar *wcs)
  2322. {
  2323. __memset(cs, 0, sizeof(col_state_t));
  2324. cs->s = wcs;
  2325. cs->bp = cs->back_buf = cs->ibb;
  2326. cs->bb_size = 128;
  2327. cs->bbe = cs->back_buf + (cs->bb_size -1);
  2328. }
  2329. static void next_weight(col_state_t *cs, int pass __LOCALE_PARAM )
  2330. {
  2331. int r, w, ru, ri, popping_backup_stack;
  2332. ssize_t n;
  2333. const uint16_t *p;
  2334. #ifdef WANT_WIDE
  2335. #define WC (*cs->s)
  2336. #define N (1)
  2337. #else /* WANT_WIDE */
  2338. wchar_t WC;
  2339. size_t n0, nx;
  2340. #define N n0
  2341. #endif /* WANT_WIDE */
  2342. do {
  2343. if (cs->ru_pushed) {
  2344. ru = cs->ru_pushed;
  2345. TRACE(("ru_pushed = %d\n", ru));
  2346. cs->ru_pushed = 0;
  2347. goto POSITION_SKIP;
  2348. }
  2349. #ifdef __UCLIBC_MJN3_ONLY__
  2350. #warning should we walk pendings backwards?
  2351. #endif
  2352. if (cs->cip) { /* possible pending weight */
  2353. if ((r = *(cs->cip++)) == 0) {
  2354. cs->cip = NULL;
  2355. continue;
  2356. }
  2357. cs->weightidx = r & WEIGHT_MASK;
  2358. assert(cs->weightidx);
  2359. /* assert(cs->weightidx != WEIGHT_MASK); */
  2360. } else { /* get the next collation item from the string */
  2361. TRACE(("clearing popping flag\n"));
  2362. popping_backup_stack = 0;
  2363. IGNORE_LOOP:
  2364. /* keep first pos as 0 for a sentinal */
  2365. if (*cs->bp) { /* pending backward chars */
  2366. POP_BACKUP:
  2367. popping_backup_stack = 1;
  2368. TRACE(("setting popping flag\n"));
  2369. n = 0;
  2370. if (*cs->bp > 0) { /* singles pending */
  2371. cs->s -= 1;
  2372. if ((*cs->bp -= 1) == 0) {
  2373. cs->bp -= 1;
  2374. }
  2375. } else { /* last was a multi */
  2376. cs->s += *cs->bp;
  2377. cs->bp -= 1;
  2378. }
  2379. } else if (!*cs->s) { /* not in backward mode and end of string */
  2380. cs->weight = 0;
  2381. return;
  2382. } else {
  2383. cs->position += 1;
  2384. }
  2385. BACK_LOOP:
  2386. #ifdef WANT_WIDE
  2387. n = 1;
  2388. cs->colitem = r = lookup(*cs->s __LOCALE_ARG );
  2389. #else /* WANT_WIDE */
  2390. n = n0 = __locale_mbrtowc_l(&WC, cs->s, __LOCALE_PTR);
  2391. if (n < 0) {
  2392. __set_errno(EILSEQ);
  2393. cs->weight = 0;
  2394. return;
  2395. }
  2396. cs->colitem = r = lookup(WC __LOCALE_ARG );
  2397. #endif /* WANT_WIDE */
  2398. TRACE((" r=%d WC=%#lx\n", r, (unsigned long)(WC)));
  2399. if (r > CUR_COLLATE->max_col_index) { /* starting char for one or more sequences */
  2400. p = CUR_COLLATE->multistart_tbl;
  2401. p += p[r-CUR_COLLATE->max_col_index -1];
  2402. do {
  2403. n = N;
  2404. r = *p++;
  2405. do {
  2406. if (!*p) { /* found it */
  2407. cs->colitem = r;
  2408. TRACE((" found multi %d\n", n));
  2409. goto FOUND;
  2410. }
  2411. #ifdef WANT_WIDE
  2412. /* the lookup check here is safe since we're assured that *p is a valid colidx */
  2413. if (!cs->s[n] || (lookup(cs->s[n] __LOCALE_ARG ) != *p)) {
  2414. do {} while (*p++);
  2415. break;
  2416. }
  2417. ++p;
  2418. ++n;
  2419. #else /* WANT_WIDE */
  2420. if (cs->s[n]) {
  2421. nx = __locale_mbrtowc_l(&WC, cs->s + n, __LOCALE_PTR);
  2422. if (nx < 0) {
  2423. __set_errno(EILSEQ);
  2424. cs->weight = 0;
  2425. return;
  2426. }
  2427. }
  2428. if (!cs->s[n] || (lookup(WC __LOCALE_ARG ) != *p)) {
  2429. do {} while (*p++);
  2430. break;
  2431. }
  2432. ++p;
  2433. n += nx; /* Only gets here if cs->s[n] != 0, so nx is set. */
  2434. #endif /* WANT_WIDE */
  2435. } while (1);
  2436. } while (1);
  2437. } else if (r == 0) { /* illegal, undefined, or part of a range */
  2438. if ((CUR_COLLATE->range_count)
  2439. #ifdef __UCLIBC_MJN3_ONLY__
  2440. #warning .. need to introduce range as a collating item?
  2441. #endif
  2442. && (((__uwchar_t)(WC - CUR_COLLATE->range_low)) <= CUR_COLLATE->range_count)
  2443. ) { /* part of a range */
  2444. /* Note: cs->colitem = 0 already. */
  2445. TRACE((" found range\n"));
  2446. ru = CUR_COLLATE->ruletable[CUR_COLLATE->range_rule_offset*CUR_COLLATE->MAX_WEIGHTS + pass];
  2447. assert((ru & WEIGHT_MASK) != DITTO_IDX);
  2448. if ((ru & WEIGHT_MASK) == WEIGHT_MASK) {
  2449. ru = (ru & RULE_MASK) | RANGE_IDX;
  2450. cs->weight = CUR_COLLATE->range_base_weight + (WC - CUR_COLLATE->range_low);
  2451. }
  2452. goto RANGE_SKIP_TO;
  2453. } else if (((__uwchar_t)(WC)) <= 0x7fffffffUL) { /* legal but undefined */
  2454. UNDEFINED:
  2455. /* Note: cs->colitem = 0 already. */
  2456. ri = CUR_COLLATE->undefined_idx;
  2457. assert(ri != 0); /* implicit undefined isn't supported */
  2458. TRACE((" found explicit UNDEFINED\n"));
  2459. #ifdef __UCLIBC_MJN3_ONLY__
  2460. #warning right now single weight locales do not support ..
  2461. #endif
  2462. if (CUR_COLLATE->num_weights == 1) {
  2463. TRACE((" single weight UNDEFINED\n"));
  2464. cs->weightidx = RANGE_IDX;
  2465. cs->weight = ri;
  2466. cs->s += n;
  2467. goto PROCESS_WEIGHT;
  2468. }
  2469. ri = CUR_COLLATE->index2ruleidx[ri - 1];
  2470. ru = CUR_COLLATE->ruletable[ri * CUR_COLLATE->MAX_WEIGHTS + pass];
  2471. assert((ru & WEIGHT_MASK) != WEIGHT_MASK); /* TODO: handle ".." */
  2472. if ((ru & WEIGHT_MASK) == DITTO_IDX) {
  2473. cs->colitem = CUR_COLLATE->undefined_idx;
  2474. }
  2475. goto RANGE_SKIP_TO;
  2476. } else { /* illegal */
  2477. TRACE((" found illegal\n"));
  2478. __set_errno(EINVAL);
  2479. /* We put all illegals in the same equiv class with maximal weight,
  2480. * and ignore them after the first pass. */
  2481. if (pass > 0) {
  2482. cs->s += n;
  2483. goto IGNORE_LOOP;
  2484. }
  2485. ru = (RULE_FORWARD | RANGE_IDX);
  2486. cs->weight = 0xffffU;
  2487. goto RANGE_SKIP_TO;
  2488. }
  2489. } else if (CUR_COLLATE->num_weights == 1) {
  2490. TRACE((" single weight\n"));
  2491. cs->weightidx = RANGE_IDX;
  2492. cs->weight = cs->colitem;
  2493. cs->s += n;
  2494. goto PROCESS_WEIGHT;
  2495. } else {
  2496. TRACE((" normal\n"));
  2497. }
  2498. /* if we get here, it is a normal char either singlely weighted, undefined, or in a range */
  2499. FOUND:
  2500. ri = CUR_COLLATE->index2ruleidx[cs->colitem - 1];
  2501. TRACE((" ri=%d ", ri));
  2502. #ifdef __UCLIBC_MJN3_ONLY__
  2503. #warning make sure this is correct
  2504. #endif
  2505. if (!ri) {
  2506. TRACE(("NOT IN THIS LOCALE\n"));
  2507. goto UNDEFINED;
  2508. }
  2509. ru = CUR_COLLATE->ruletable[ri * CUR_COLLATE->MAX_WEIGHTS + pass];
  2510. RANGE_SKIP_TO:
  2511. #ifdef __UCLIBC_MJN3_ONLY__
  2512. #warning ignoreables probably should not interrupt backwards processing, but this is wrong
  2513. #endif
  2514. /* if (!(ru & WEIGHT_MASK)) { */
  2515. /* TRACE(("IGNORE\n")); */
  2516. /* cs->s += n; */
  2517. /* continue; */
  2518. /* } */
  2519. TRACE((" rule = %#x weight = %#x popping = %d s = %p eob = %p\n",
  2520. ru & RULE_MASK, ru & WEIGHT_MASK, popping_backup_stack,
  2521. cs->s, cs->eob));
  2522. /* now we need to check if we're going backwards... */
  2523. if (!popping_backup_stack) {
  2524. if (!(ru & RULE_MASK)) { /* backward */
  2525. TRACE(("backwards\n"));
  2526. assert(cs->bp <= cs->bbe);
  2527. if (cs->bp == cs->bbe) {
  2528. if (cs->back_buf == cs->ibb) { /* was using internal buffer */
  2529. cs->bp = malloc(cs->bb_size + 128);
  2530. if (!cs->bp) {
  2531. __set_errno(ENOMEM);
  2532. #ifdef __UCLIBC_MJN3_ONLY__
  2533. #warning what to do here?
  2534. #endif
  2535. cs->weight = 0;
  2536. return;
  2537. }
  2538. __memcpy(cs->bp, cs->back_buf, cs->bb_size);
  2539. } else {
  2540. cs->bp = realloc(cs->back_buf, cs->bb_size + 128);
  2541. if (!cs->bp) {
  2542. __set_errno(ENOMEM);
  2543. #ifdef __UCLIBC_MJN3_ONLY__
  2544. #warning what to do here?
  2545. #endif
  2546. cs->weight = 0;
  2547. return;
  2548. }
  2549. }
  2550. cs->bb_size += 128;
  2551. cs->bbe = cs->bp + (cs->bbe - cs->back_buf);
  2552. cs->back_buf = cs->bp;
  2553. cs->bp = cs->bbe;
  2554. }
  2555. if (n==1) { /* single char */
  2556. if (*cs->bp && (((unsigned char)(*cs->bp)) < CHAR_MAX)) {
  2557. *cs->bp += 1; /* increment last single's count */
  2558. } else { /* last was a multi, or just starting */
  2559. if (!cs->bp) {
  2560. cs->bp = cs->back_buf;
  2561. } else {
  2562. assert(cs->bp < cs->bbe);
  2563. ++cs->bp;
  2564. }
  2565. *cs->bp = 1;
  2566. }
  2567. } else { /* multichar */
  2568. assert(n>1);
  2569. assert(cs->bp < cs->bbe);
  2570. *++cs->bp = -n;
  2571. }
  2572. cs->s += n;
  2573. if (*cs->s) {
  2574. goto BACK_LOOP;
  2575. }
  2576. /* end-of-string so start popping */
  2577. cs->eob = cs->s;
  2578. TRACE(("popping\n"));
  2579. goto POP_BACKUP;
  2580. } else if (*cs->bp) { /* was going backward but this element isn't */
  2581. /* discard current and use previous backward element */
  2582. assert(!cs->cip);
  2583. cs->eob = cs->s;
  2584. TRACE(("popping\n"));
  2585. goto POP_BACKUP;
  2586. } else { /* was and still going forward */
  2587. TRACE(("forwards\n"));
  2588. if ((ru & (RULE_POSITION|WEIGHT_MASK)) > RULE_POSITION) {
  2589. assert(ru & WEIGHT_MASK);
  2590. cs->ru_pushed = ru;
  2591. cs->weight = cs->position;
  2592. #ifdef __UCLIBC_MJN3_ONLY__
  2593. #warning devel code
  2594. #endif
  2595. cs->position = 0; /* reset to reduce size for strcoll? */
  2596. cs->s += n;
  2597. cs->weightidx = RANGE_IDX;
  2598. goto PROCESS_WEIGHT;
  2599. }
  2600. }
  2601. } else { /* popping backwards stack */
  2602. TRACE(("popping (continued)\n"));
  2603. if (!*cs->bp) {
  2604. cs->s = cs->eob;
  2605. }
  2606. cs->s -= n;
  2607. }
  2608. cs->s += n;
  2609. POSITION_SKIP:
  2610. cs->weightidx = ru & WEIGHT_MASK;
  2611. cs->rule = ru & RULE_MASK;
  2612. }
  2613. #ifdef __UCLIBC_MJN3_ONLY__
  2614. #warning for pending we only want the weight... _not_ the rule
  2615. #endif
  2616. if (!cs->weightidx) { /* ignore */
  2617. continue;
  2618. }
  2619. PROCESS_WEIGHT:
  2620. assert(cs->weightidx);
  2621. if (((unsigned int)(cs->weightidx - UI_IDX)) <= (INVAL_IDX-UI_IDX)) {
  2622. if (cs->weightidx == UI_IDX) {
  2623. cs->weight = cs->ui_weight;
  2624. }
  2625. return;
  2626. }
  2627. assert(cs->weightidx != WEIGHT_MASK);
  2628. if (cs->weightidx == DITTO_IDX) { /* want the weight of the current collating item */
  2629. TRACE(("doing ditto\n"));
  2630. w = CUR_COLLATE->index2weight[cs->colitem -1];
  2631. } else if (cs->weightidx <= CUR_COLLATE->max_col_index) { /* normal */
  2632. TRACE(("doing normal\n"));
  2633. w = CUR_COLLATE->index2weight[cs->weightidx -1];
  2634. } else { /* a string */
  2635. TRACE(("doing string\n"));
  2636. assert(!(cs->weightidx & RULE_MASK));
  2637. /* note: iso14561 allows null string here */
  2638. p = CUR_COLLATE->weightstr + (cs->weightidx - (CUR_COLLATE->max_col_index + 2));
  2639. if (*p & WEIGHT_MASK) {
  2640. r = 0;
  2641. do {
  2642. assert(r < MAX_PENDING);
  2643. cs->ci_pending[r++] = *p++;
  2644. } while (*p & WEIGHT_MASK);
  2645. cs->cip = cs->ci_pending;
  2646. }
  2647. continue;
  2648. }
  2649. cs->weight = w;
  2650. return;
  2651. } while (1);
  2652. }
  2653. int __XL(wcscoll) (const Wchar *s0, const Wchar *s1 __LOCALE_PARAM )
  2654. {
  2655. col_state_t ws[2];
  2656. int pass;
  2657. if (!CUR_COLLATE->num_weights) { /* C locale */
  2658. #ifdef WANT_WIDE
  2659. return wcscmp(s0, s1);
  2660. #else /* WANT_WIDE */
  2661. return strcmp(s0, s1);
  2662. #endif /* WANT_WIDE */
  2663. }
  2664. pass = 0;
  2665. do { /* loop through the weights levels */
  2666. init_col_state(ws, s0);
  2667. init_col_state(ws+1, s1);
  2668. do { /* loop through the strings */
  2669. /* for each string, get the next weight */
  2670. next_weight(ws, pass __LOCALE_ARG );
  2671. next_weight(ws+1, pass __LOCALE_ARG );
  2672. TRACE(("w0=%lu w1=%lu\n",
  2673. (unsigned long) ws[0].weight,
  2674. (unsigned long) ws[1].weight));
  2675. if (ws[0].weight != ws[1].weight) {
  2676. return ws[0].weight - ws[1].weight;
  2677. }
  2678. } while (ws[0].weight);
  2679. } while (++pass < CUR_COLLATE->num_weights);
  2680. return 0;
  2681. }
  2682. __XL_ALIAS(wcscoll)
  2683. #ifdef WANT_WIDE
  2684. size_t __XL(wcsxfrm)(wchar_t *__restrict ws1, const wchar_t *__restrict ws2,
  2685. size_t n __LOCALE_PARAM )
  2686. {
  2687. col_state_t cs;
  2688. size_t count;
  2689. int pass;
  2690. if (!CUR_COLLATE->num_weights) { /* C locale */
  2691. return wcsxfrm(ws1, ws2, n);
  2692. }
  2693. #ifdef __UCLIBC_MJN3_ONLY__
  2694. #warning handle empty string as a special case
  2695. #endif
  2696. count = pass = 0;
  2697. do { /* loop through the weights levels */
  2698. init_col_state(&cs, ws2);
  2699. do { /* loop through the string */
  2700. next_weight(&cs, pass __LOCALE_ARG );
  2701. TRACE(("weight=%lu (%#lx)\n", (unsigned long) cs.weight, (unsigned long) cs.weight));
  2702. if (count < n) {
  2703. ws1[count] = cs.weight +1;
  2704. }
  2705. ++count;
  2706. TRACE(("--------------------------------------------\n"));
  2707. } while (cs.weight);
  2708. if (count <= n) { /* overwrite the trailing 0 end-of-pass marker */
  2709. ws1[count-1] = 1;
  2710. }
  2711. TRACE(("-------------------- pass %d --------------------\n", pass));
  2712. } while (++pass < CUR_COLLATE->num_weights);
  2713. if (count <= n) { /* oops... change it back */
  2714. ws1[count-1] = 0;
  2715. }
  2716. return count-1;
  2717. }
  2718. __XL_ALIAS(wcsxfrm)
  2719. #else /* WANT_WIDE */
  2720. static const unsigned long bound[] = {
  2721. 1UL << 7,
  2722. 1UL << 11,
  2723. 1UL << 16,
  2724. 1UL << 21,
  2725. 1UL << 26,
  2726. };
  2727. static unsigned char first[] = {
  2728. 0x0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc
  2729. };
  2730. /* Use an extension of UTF-8 to store a 32 bit val in max 6 bytes. */
  2731. static size_t store(unsigned char *s, size_t count, size_t n, __uwchar_t weight)
  2732. {
  2733. int i, r;
  2734. i = 0;
  2735. do {
  2736. if (weight < bound[i]) {
  2737. break;
  2738. }
  2739. } while (++i < sizeof(bound)/sizeof(bound[0]));
  2740. r = i+1;
  2741. if (i + count < n) {
  2742. s += count;
  2743. s[0] = first[i];
  2744. while (i) {
  2745. s[i] = 0x80 | (weight & 0x3f);
  2746. weight >>= 6;
  2747. --i;
  2748. }
  2749. s[0] |= weight;
  2750. }
  2751. return r;
  2752. }
  2753. size_t __XL(strxfrm)(char *__restrict ws1, const char *__restrict ws2, size_t n
  2754. __LOCALE_PARAM )
  2755. {
  2756. col_state_t cs;
  2757. size_t count, inc;
  2758. int pass;
  2759. if (!CUR_COLLATE->num_weights) { /* C locale */
  2760. return strlcpy(ws1, ws2, n);
  2761. }
  2762. #ifdef __UCLIBC_MJN3_ONLY__
  2763. #warning handle empty string as a special case
  2764. #endif
  2765. inc = count = pass = 0;
  2766. do { /* loop through the weights levels */
  2767. init_col_state(&cs, ws2);
  2768. do { /* loop through the string */
  2769. next_weight(&cs, pass __LOCALE_ARG );
  2770. TRACE(("weight=%lu (%#lx)\n", (unsigned long) cs.weight, (unsigned long) cs.weight));
  2771. inc = store((unsigned char *)ws1, count, n, cs.weight + 1);
  2772. count += inc;
  2773. TRACE(("--------------------------------------------\n"));
  2774. } while (cs.weight);
  2775. /* overwrite the trailing 0 end-of-pass marker */
  2776. assert(inc == 1);
  2777. if (count <= n) {
  2778. ws1[count-1] = 1;
  2779. }
  2780. TRACE(("-------------------- pass %d --------------------\n", pass));
  2781. } while (++pass < CUR_COLLATE->num_weights);
  2782. if (count <= n) { /* oops... change it back */
  2783. ws1[count-1] = 0;
  2784. }
  2785. return count-1;
  2786. }
  2787. __XL_ALIAS(strxfrm)
  2788. #endif /* WANT_WIDE */
  2789. #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  2790. #endif /* defined(L_strxfrm) || defined(L_strxfrm_l) || defined(L_wcsxfrm) || defined(L_wcsxfrm_l) */
  2791. #endif /* __LOCALE_C_ONLY */
  2792. /**********************************************************************/