wstring.c 73 KB

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