wstring.c 71 KB

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