wstring.c 71 KB

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