wstring.c 71 KB

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