wstring.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147
  1. /* Copyright (C) 2002 Manuel Novoa III
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Library General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Library General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Library General Public
  14. * License along with this library; if not, write to the Free
  15. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. /* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
  18. *
  19. * Besides uClibc, I'm using this code in my libc for elks, which is
  20. * a 16-bit environment with a fairly limited compiler. It would make
  21. * things much easier for me if this file isn't modified unnecessarily.
  22. * In particular, please put any new or replacement functions somewhere
  23. * else, and modify the makefile to use your version instead.
  24. * Thanks. Manuel
  25. *
  26. * ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! */
  27. #define _STDIO_UTILITY
  28. #define _GNU_SOURCE
  29. #include <string.h>
  30. #include <strings.h>
  31. #include <stdio.h>
  32. #include <limits.h>
  33. #include <ctype.h>
  34. #include <stdlib.h>
  35. #include <errno.h>
  36. #include <signal.h>
  37. #ifdef WANT_WIDE
  38. #include <wchar.h>
  39. #include <wctype.h>
  40. #include <locale.h>
  41. #define Wvoid wchar_t
  42. #define Wchar wchar_t
  43. #define Wuchar __uwchar_t
  44. #define Wint wchar_t
  45. #else
  46. #define Wvoid void
  47. #define Wchar char
  48. typedef unsigned char __string_uchar_t;
  49. #define Wuchar __string_uchar_t
  50. #define Wint int
  51. #endif
  52. /**********************************************************************/
  53. /* NOTE: If we ever do internationalized syserr messages, this will
  54. * have to be changed! */
  55. #define _SYS_NERR 125
  56. #if defined(__mips__) || defined(__sparc__)
  57. /* sparce and mips have an extra error entry, as EDEADLK and EDEADLOCK have
  58. * different meanings on those platforms. */
  59. #undef _SYS_NERR
  60. #define _SYS_NERR 126
  61. #endif
  62. #define _SYS_ERRMSG_MAXLEN 50
  63. extern const char _string_syserrmsgs[];
  64. #define _SYS_NSIG 32
  65. #define _SYS_SIGMSG_MAXLEN 25
  66. extern const char _string_syssigmsgs[];
  67. #if _SYS_ERRMSG_MAXLEN < __UIM_BUFLEN_INT + 14
  68. #define _STRERROR_BUFSIZE (__UIM_BUFLEN_INT + 14)
  69. #else
  70. #define _STRERROR_BUFSIZE _SYS_ERRMSG_MAXLEN
  71. #endif
  72. #if _SYS_SIGMSG_MAXLEN < __UIM_BUFLEN_INT + 14
  73. #define _STRSIGNAL_BUFSIZE (__UIM_BUFLEN_INT + 14)
  74. #else
  75. #define _STRSIGNAL_BUFSIZE _SYS_SIGMSG_MAXLEN
  76. #endif
  77. /**********************************************************************/
  78. #ifdef L__string_syserrmsgs
  79. const char _string_syserrmsgs[] = {
  80. /* 0: 0, 8 */ "Success\0"
  81. /* 1: 8, 24 */ "Operation not permitted\0"
  82. /* 2: 32, 26 */ "No such file or directory\0"
  83. /* 3: 58, 16 */ "No such process\0"
  84. /* 4: 74, 24 */ "Interrupted system call\0"
  85. /* 5: 98, 19 */ "Input/output error\0"
  86. /* 6: 117, 26 */ "No such device or address\0"
  87. /* 7: 143, 23 */ "Argument list too long\0"
  88. /* 8: 166, 18 */ "Exec format error\0"
  89. /* 9: 184, 20 */ "Bad file descriptor\0"
  90. /* 10: 204, 19 */ "No child processes\0"
  91. /* 11: 223, 33 */ "Resource temporarily unavailable\0"
  92. /* 12: 256, 23 */ "Cannot allocate memory\0"
  93. /* 13: 279, 18 */ "Permission denied\0"
  94. /* 14: 297, 12 */ "Bad address\0"
  95. /* 15: 309, 22 */ "Block device required\0"
  96. /* 16: 331, 24 */ "Device or resource busy\0"
  97. /* 17: 355, 12 */ "File exists\0"
  98. /* 18: 367, 26 */ "Invalid cross-device link\0"
  99. /* 19: 393, 15 */ "No such device\0"
  100. /* 20: 408, 16 */ "Not a directory\0"
  101. /* 21: 424, 15 */ "Is a directory\0"
  102. /* 22: 439, 17 */ "Invalid argument\0"
  103. /* 23: 456, 30 */ "Too many open files in system\0"
  104. /* 24: 486, 20 */ "Too many open files\0"
  105. /* 25: 506, 31 */ "Inappropriate ioctl for device\0"
  106. /* 26: 537, 15 */ "Text file busy\0"
  107. /* 27: 552, 15 */ "File too large\0"
  108. /* 28: 567, 24 */ "No space left on device\0"
  109. /* 29: 591, 13 */ "Illegal seek\0"
  110. /* 30: 604, 22 */ "Read-only file system\0"
  111. /* 31: 626, 15 */ "Too many links\0"
  112. /* 32: 641, 12 */ "Broken pipe\0"
  113. /* 33: 653, 33 */ "Numerical argument out of domain\0"
  114. /* 34: 686, 30 */ "Numerical result out of range\0"
  115. /* 35: 716, 26 */ "Resource deadlock avoided\0"
  116. /* 36: 742, 19 */ "File name too long\0"
  117. /* 37: 761, 19 */ "No locks available\0"
  118. /* 38: 780, 25 */ "Function not implemented\0"
  119. /* 39: 805, 20 */ "Directory not empty\0"
  120. /* 40: 825, 34 */ "Too many levels of symbolic links\0"
  121. /* 41: 859, 1 */ "\0"
  122. /* 42: 860, 27 */ "No message of desired type\0"
  123. /* 43: 887, 19 */ "Identifier removed\0"
  124. /* 44: 906, 28 */ "Channel number out of range\0"
  125. /* 45: 934, 25 */ "Level 2 not synchronized\0"
  126. /* 46: 959, 15 */ "Level 3 halted\0"
  127. /* 47: 974, 14 */ "Level 3 reset\0"
  128. /* 48: 988, 25 */ "Link number out of range\0"
  129. /* 49: 1013, 29 */ "Protocol driver not attached\0"
  130. /* 50: 1042, 27 */ "No CSI structure available\0"
  131. /* 51: 1069, 15 */ "Level 2 halted\0"
  132. /* 52: 1084, 17 */ "Invalid exchange\0"
  133. /* 53: 1101, 27 */ "Invalid request descriptor\0"
  134. /* 54: 1128, 14 */ "Exchange full\0"
  135. /* 55: 1142, 9 */ "No anode\0"
  136. /* 56: 1151, 21 */ "Invalid request code\0"
  137. /* 57: 1172, 13 */ "Invalid slot\0"
  138. /* 58: 1185, 1 */ "\0"
  139. /* 59: 1186, 21 */ "Bad font file format\0"
  140. /* 60: 1207, 20 */ "Device not a stream\0"
  141. /* 61: 1227, 18 */ "No data available\0"
  142. /* 62: 1245, 14 */ "Timer expired\0"
  143. /* 63: 1259, 25 */ "Out of streams resources\0"
  144. /* 64: 1284, 30 */ "Machine is not on the network\0"
  145. /* 65: 1314, 22 */ "Package not installed\0"
  146. /* 66: 1336, 17 */ "Object is remote\0"
  147. /* 67: 1353, 22 */ "Link has been severed\0"
  148. /* 68: 1375, 16 */ "Advertise error\0"
  149. /* 69: 1391, 14 */ "Srmount error\0"
  150. /* 70: 1405, 28 */ "Communication error on send\0"
  151. /* 71: 1433, 15 */ "Protocol error\0"
  152. /* 72: 1448, 19 */ "Multihop attempted\0"
  153. /* 73: 1467, 19 */ "RFS specific error\0"
  154. /* 74: 1486, 12 */ "Bad message\0"
  155. /* 75: 1498, 38 */ "Value too large for defined data type\0"
  156. /* 76: 1536, 27 */ "Name not unique on network\0"
  157. /* 77: 1563, 29 */ "File descriptor in bad state\0"
  158. /* 78: 1592, 23 */ "Remote address changed\0"
  159. /* 79: 1615, 39 */ "Can not access a needed shared library\0"
  160. /* 80: 1654, 37 */ "Accessing a corrupted shared library\0"
  161. /* 81: 1691, 32 */ ".lib section in a.out corrupted\0"
  162. /* 82: 1723, 48 */ "Attempting to link in too many shared libraries\0"
  163. /* 83: 1771, 38 */ "Cannot exec a shared library directly\0"
  164. /* 84: 1809, 50 */ "Invalid or incomplete multibyte or wide character\0"
  165. /* 85: 1859, 44 */ "Interrupted system call should be restarted\0"
  166. /* 86: 1903, 19 */ "Streams pipe error\0"
  167. /* 87: 1922, 15 */ "Too many users\0"
  168. /* 88: 1937, 31 */ "Socket operation on non-socket\0"
  169. /* 89: 1968, 29 */ "Destination address required\0"
  170. /* 90: 1997, 17 */ "Message too long\0"
  171. /* 91: 2014, 31 */ "Protocol wrong type for socket\0"
  172. /* 92: 2045, 23 */ "Protocol not available\0"
  173. /* 93: 2068, 23 */ "Protocol not supported\0"
  174. /* 94: 2091, 26 */ "Socket type not supported\0"
  175. /* 95: 2117, 24 */ "Operation not supported\0"
  176. /* 96: 2141, 30 */ "Protocol family not supported\0"
  177. /* 97: 2171, 41 */ "Address family not supported by protocol\0"
  178. /* 98: 2212, 23 */ "Address already in use\0"
  179. /* 99: 2235, 32 */ "Cannot assign requested address\0"
  180. /* 100: 2267, 16 */ "Network is down\0"
  181. /* 101: 2283, 23 */ "Network is unreachable\0"
  182. /* 102: 2306, 36 */ "Network dropped connection on reset\0"
  183. /* 103: 2342, 33 */ "Software caused connection abort\0"
  184. /* 104: 2375, 25 */ "Connection reset by peer\0"
  185. /* 105: 2400, 26 */ "No buffer space available\0"
  186. /* 106: 2426, 40 */ "Transport endpoint is already connected\0"
  187. /* 107: 2466, 36 */ "Transport endpoint is not connected\0"
  188. /* 108: 2502, 46 */ "Cannot send after transport endpoint shutdown\0"
  189. /* 109: 2548, 35 */ "Too many references: cannot splice\0"
  190. /* 110: 2583, 21 */ "Connection timed out\0"
  191. /* 111: 2604, 19 */ "Connection refused\0"
  192. /* 112: 2623, 13 */ "Host is down\0"
  193. /* 113: 2636, 17 */ "No route to host\0"
  194. /* 114: 2653, 30 */ "Operation already in progress\0"
  195. /* 115: 2683, 26 */ "Operation now in progress\0"
  196. /* 116: 2709, 22 */ "Stale NFS file handle\0"
  197. /* 117: 2731, 25 */ "Structure needs cleaning\0"
  198. /* 118: 2756, 28 */ "Not a XENIX named type file\0"
  199. /* 119: 2784, 30 */ "No XENIX semaphores available\0"
  200. /* 120: 2814, 21 */ "Is a named type file\0"
  201. /* 121: 2835, 17 */ "Remote I/O error\0"
  202. /* 122: 2852, 20 */ "Disk quota exceeded\0"
  203. /* 123: 2872, 16 */ "No medium found\0"
  204. /* 124: 2888, 18 */ "Wrong medium type"
  205. #if defined(__mips__) || defined(__sparc__)
  206. "\0"
  207. /* 125: 2906, 28 */ "File locking deadlock error"
  208. #endif
  209. /* Note: for mips we are ignoring ECANCELED since glibc doesn't have a
  210. * corresponsding message.*/
  211. };
  212. #endif
  213. /**********************************************************************/
  214. #ifdef L_sys_errlist
  215. 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.")
  216. const char *const sys_errlist[] = {
  217. [0] = _string_syserrmsgs + 0,
  218. [EPERM] = _string_syserrmsgs + 8,
  219. [ENOENT] = _string_syserrmsgs + 32,
  220. [ESRCH] = _string_syserrmsgs + 58,
  221. [EINTR] = _string_syserrmsgs + 74,
  222. [EIO] = _string_syserrmsgs + 98,
  223. [ENXIO] = _string_syserrmsgs + 117,
  224. [E2BIG] = _string_syserrmsgs + 143,
  225. [ENOEXEC] = _string_syserrmsgs + 166,
  226. [EBADF] = _string_syserrmsgs + 184,
  227. [ECHILD] = _string_syserrmsgs + 204,
  228. [EAGAIN] = _string_syserrmsgs + 223,
  229. [ENOMEM] = _string_syserrmsgs + 256,
  230. [EACCES] = _string_syserrmsgs + 279,
  231. [EFAULT] = _string_syserrmsgs + 297,
  232. [ENOTBLK] = _string_syserrmsgs + 309,
  233. [EBUSY] = _string_syserrmsgs + 331,
  234. [EEXIST] = _string_syserrmsgs + 355,
  235. [EXDEV] = _string_syserrmsgs + 367,
  236. [ENODEV] = _string_syserrmsgs + 393,
  237. [ENOTDIR] = _string_syserrmsgs + 408,
  238. [EISDIR] = _string_syserrmsgs + 424,
  239. [EINVAL] = _string_syserrmsgs + 439,
  240. [ENFILE] = _string_syserrmsgs + 456,
  241. [EMFILE] = _string_syserrmsgs + 486,
  242. [ENOTTY] = _string_syserrmsgs + 506,
  243. [ETXTBSY] = _string_syserrmsgs + 537,
  244. [EFBIG] = _string_syserrmsgs + 552,
  245. [ENOSPC] = _string_syserrmsgs + 567,
  246. [ESPIPE] = _string_syserrmsgs + 591,
  247. [EROFS] = _string_syserrmsgs + 604,
  248. [EMLINK] = _string_syserrmsgs + 626,
  249. [EPIPE] = _string_syserrmsgs + 641,
  250. [EDOM] = _string_syserrmsgs + 653,
  251. [ERANGE] = _string_syserrmsgs + 686,
  252. [EDEADLK] = _string_syserrmsgs + 716,
  253. [ENAMETOOLONG] = _string_syserrmsgs + 742,
  254. [ENOLCK] = _string_syserrmsgs + 761,
  255. [ENOSYS] = _string_syserrmsgs + 780,
  256. [ENOTEMPTY] = _string_syserrmsgs + 805,
  257. [ELOOP] = _string_syserrmsgs + 825,
  258. /* _string_syserrmsgs + 859, */
  259. [ENOMSG] = _string_syserrmsgs + 860,
  260. [EIDRM] = _string_syserrmsgs + 887,
  261. [ECHRNG] = _string_syserrmsgs + 906,
  262. [EL2NSYNC] = _string_syserrmsgs + 934,
  263. [EL3HLT] = _string_syserrmsgs + 959,
  264. [EL3RST] = _string_syserrmsgs + 974,
  265. [ELNRNG] = _string_syserrmsgs + 988,
  266. [EUNATCH] = _string_syserrmsgs + 1013,
  267. [ENOCSI] = _string_syserrmsgs + 1042,
  268. [EL2HLT] = _string_syserrmsgs + 1069,
  269. [EBADE] = _string_syserrmsgs + 1084,
  270. [EBADR] = _string_syserrmsgs + 1101,
  271. [EXFULL] = _string_syserrmsgs + 1128,
  272. [ENOANO] = _string_syserrmsgs + 1142,
  273. [EBADRQC] = _string_syserrmsgs + 1151,
  274. [EBADSLT] = _string_syserrmsgs + 1172,
  275. /* _string_syserrmsgs + 1185, */
  276. [EBFONT] = _string_syserrmsgs + 1186,
  277. [ENOSTR] = _string_syserrmsgs + 1207,
  278. [ENODATA] = _string_syserrmsgs + 1227,
  279. [ETIME] = _string_syserrmsgs + 1245,
  280. [ENOSR] = _string_syserrmsgs + 1259,
  281. [ENONET] = _string_syserrmsgs + 1284,
  282. [ENOPKG] = _string_syserrmsgs + 1314,
  283. [EREMOTE] = _string_syserrmsgs + 1336,
  284. [ENOLINK] = _string_syserrmsgs + 1353,
  285. [EADV] = _string_syserrmsgs + 1375,
  286. [ESRMNT] = _string_syserrmsgs + 1391,
  287. [ECOMM] = _string_syserrmsgs + 1405,
  288. [EPROTO] = _string_syserrmsgs + 1433,
  289. [EMULTIHOP] = _string_syserrmsgs + 1448,
  290. [EDOTDOT] = _string_syserrmsgs + 1467,
  291. [EBADMSG] = _string_syserrmsgs + 1486,
  292. [EOVERFLOW] = _string_syserrmsgs + 1498,
  293. [ENOTUNIQ] = _string_syserrmsgs + 1536,
  294. [EBADFD] = _string_syserrmsgs + 1563,
  295. [EREMCHG] = _string_syserrmsgs + 1592,
  296. [ELIBACC] = _string_syserrmsgs + 1615,
  297. [ELIBBAD] = _string_syserrmsgs + 1654,
  298. [ELIBSCN] = _string_syserrmsgs + 1691,
  299. [ELIBMAX] = _string_syserrmsgs + 1723,
  300. [ELIBEXEC] = _string_syserrmsgs + 1771,
  301. [EILSEQ] = _string_syserrmsgs + 1809,
  302. [ERESTART] = _string_syserrmsgs + 1859,
  303. [ESTRPIPE] = _string_syserrmsgs + 1903,
  304. [EUSERS] = _string_syserrmsgs + 1922,
  305. [ENOTSOCK] = _string_syserrmsgs + 1937,
  306. [EDESTADDRREQ] = _string_syserrmsgs + 1968,
  307. [EMSGSIZE] = _string_syserrmsgs + 1997,
  308. [EPROTOTYPE] = _string_syserrmsgs + 2014,
  309. [ENOPROTOOPT] = _string_syserrmsgs + 2045,
  310. [EPROTONOSUPPORT] = _string_syserrmsgs + 2068,
  311. [ESOCKTNOSUPPORT] = _string_syserrmsgs + 2091,
  312. [EOPNOTSUPP] = _string_syserrmsgs + 2117,
  313. [EPFNOSUPPORT] = _string_syserrmsgs + 2141,
  314. [EAFNOSUPPORT] = _string_syserrmsgs + 2171,
  315. [EADDRINUSE] = _string_syserrmsgs + 2212,
  316. [EADDRNOTAVAIL] = _string_syserrmsgs + 2235,
  317. [ENETDOWN] = _string_syserrmsgs + 2267,
  318. [ENETUNREACH] = _string_syserrmsgs + 2283,
  319. [ENETRESET] = _string_syserrmsgs + 2306,
  320. [ECONNABORTED] = _string_syserrmsgs + 2342,
  321. [ECONNRESET] = _string_syserrmsgs + 2375,
  322. [ENOBUFS] = _string_syserrmsgs + 2400,
  323. [EISCONN] = _string_syserrmsgs + 2426,
  324. [ENOTCONN] = _string_syserrmsgs + 2466,
  325. [ESHUTDOWN] = _string_syserrmsgs + 2502,
  326. [ETOOMANYREFS] = _string_syserrmsgs + 2548,
  327. [ETIMEDOUT] = _string_syserrmsgs + 2583,
  328. [ECONNREFUSED] = _string_syserrmsgs + 2604,
  329. [EHOSTDOWN] = _string_syserrmsgs + 2623,
  330. [EHOSTUNREACH] = _string_syserrmsgs + 2636,
  331. [EALREADY] = _string_syserrmsgs + 2653,
  332. [EINPROGRESS] = _string_syserrmsgs + 2683,
  333. [ESTALE] = _string_syserrmsgs + 2709,
  334. [EUCLEAN] = _string_syserrmsgs + 2731,
  335. [ENOTNAM] = _string_syserrmsgs + 2756,
  336. [ENAVAIL] = _string_syserrmsgs + 2784,
  337. [EISNAM] = _string_syserrmsgs + 2814,
  338. [EREMOTEIO] = _string_syserrmsgs + 2835,
  339. [EDQUOT] = _string_syserrmsgs + 2852,
  340. [ENOMEDIUM] = _string_syserrmsgs + 2872,
  341. [EMEDIUMTYPE] = _string_syserrmsgs + 2888,
  342. #if EDEADLOCK != EDEADLK
  343. [EDEADLOCK] = _string_syserrmsgs + 2906,
  344. #endif
  345. #if EWOULDBLOCK != EAGAIN
  346. #error EWOULDBLOCK does not equal EAGAIN
  347. #endif
  348. /* For now, ignore the other arch-specific errors. glibc only maps EPROCLIM. */
  349. /* some other mips errors */
  350. #ifdef ECANCELED
  351. #endif
  352. #ifdef EINIT
  353. #endif
  354. #ifdef EREMDEV
  355. #endif
  356. /* some other sparc errors */
  357. #ifdef EPROCLIM
  358. #endif
  359. #ifdef ERREMOTE
  360. #endif
  361. };
  362. int sys_nerr = sizeof(sys_errlist)/sizeof(sys_errlist[0]);
  363. #endif
  364. /**********************************************************************/
  365. #ifdef L_wmemcpy
  366. #define L_memcpy
  367. #define Wmemcpy wmemcpy
  368. #else
  369. #define Wmemcpy memcpy
  370. #endif
  371. #ifdef L_memcpy
  372. Wvoid *Wmemcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
  373. {
  374. register Wchar *r1 = s1;
  375. register const Wchar *r2 = s2;
  376. #ifdef __BCC__
  377. while (n--) {
  378. *r1++ = *r2++;
  379. }
  380. #else
  381. while (n) {
  382. *r1++ = *r2++;
  383. --n;
  384. }
  385. #endif
  386. return s1;
  387. }
  388. #endif
  389. /**********************************************************************/
  390. #ifdef L_wmemmove
  391. #define L_memmove
  392. #define Wmemmove wmemmove
  393. #else
  394. #define Wmemmove memmove
  395. #endif
  396. #ifdef L_memmove
  397. Wvoid *Wmemmove(Wvoid *s1, const Wvoid *s2, size_t n)
  398. {
  399. #ifdef __BCC__
  400. register Wchar *s = (Wchar *) s1;
  401. register const Wchar *p = (const Wchar *) s2;
  402. if (p >= s) {
  403. while (n--) {
  404. *s++ = *p++;
  405. }
  406. } else {
  407. s += n;
  408. p += n;
  409. while (n--) {
  410. *--s = *--p;
  411. }
  412. }
  413. return s1;
  414. #else
  415. register Wchar *s = (Wchar *) s1;
  416. register const Wchar *p = (const Wchar *) s2;
  417. if (p >= s) {
  418. while (n) {
  419. *s++ = *p++;
  420. --n;
  421. }
  422. } else {
  423. while (n) {
  424. --n;
  425. s[n] = p[n];
  426. }
  427. }
  428. return s1;
  429. #endif
  430. }
  431. #endif
  432. /**********************************************************************/
  433. #ifdef L_wcscpy
  434. #define L_strcpy
  435. #define Wstrcpy wcscpy
  436. #else
  437. #define Wstrcpy strcpy
  438. #endif
  439. #ifdef L_strcpy
  440. Wchar *Wstrcpy(Wchar * __restrict s1, const Wchar * __restrict s2)
  441. {
  442. register Wchar *s = s1;
  443. #ifdef __BCC__
  444. do {
  445. *s = *s2++;
  446. } while (*s++ != 0);
  447. #else
  448. while ( (*s++ = *s2++) != 0 );
  449. #endif
  450. return s1;
  451. }
  452. #endif
  453. /**********************************************************************/
  454. #ifdef L_wcsncpy
  455. #define L_strncpy
  456. #define Wstrncpy wcsncpy
  457. #else
  458. #define Wstrncpy strncpy
  459. #endif
  460. #ifdef L_strncpy
  461. Wchar *Wstrncpy(Wchar * __restrict s1, register const Wchar * __restrict s2,
  462. size_t n)
  463. {
  464. register Wchar *s = s1;
  465. #ifdef __BCC__
  466. while (n--) {
  467. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  468. ++s;
  469. }
  470. #else
  471. while (n) {
  472. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  473. ++s;
  474. --n;
  475. }
  476. #endif
  477. return s1;
  478. }
  479. #endif
  480. /**********************************************************************/
  481. #ifdef L_wcscat
  482. #define L_strcat
  483. #define Wstrcat wcscat
  484. #else
  485. #define Wstrcat strcat
  486. #endif
  487. #ifdef L_strcat
  488. Wchar *Wstrcat(Wchar * __restrict s1, register const Wchar * __restrict s2)
  489. {
  490. register Wchar *s = s1;
  491. while (*s++);
  492. --s;
  493. while ((*s++ = *s2++) != 0);
  494. return s1;
  495. }
  496. #endif
  497. /**********************************************************************/
  498. #ifdef L_wcsncat
  499. #define L_strncat
  500. #define Wstrncat wcsncat
  501. #else
  502. #define Wstrncat strncat
  503. #endif
  504. #ifdef L_strncat
  505. Wchar *Wstrncat(Wchar * __restrict s1, register const Wchar * __restrict s2,
  506. size_t n)
  507. {
  508. register Wchar *s = s1;
  509. while (*s++);
  510. --s;
  511. #if __BCC__
  512. while (n-- && ((*s = *s2++) != 0)) ++s;
  513. #else
  514. while (n && ((*s = *s2++) != 0)) {
  515. --n;
  516. ++s;
  517. }
  518. #endif
  519. *s = 0;
  520. return s1;
  521. }
  522. #endif
  523. /**********************************************************************/
  524. #ifdef L_wmemcmp
  525. #define L_memcmp
  526. #define Wmemcmp wmemcmp
  527. #else
  528. #define Wmemcmp memcmp
  529. #endif
  530. #ifdef L_memcmp
  531. #ifndef L_wmemcmp
  532. weak_alias(memcmp,bcmp);
  533. #endif
  534. int Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n)
  535. {
  536. register const Wuchar *r1 = (const Wuchar *) s1;
  537. register const Wuchar *r2 = (const Wuchar *) s2;
  538. #ifdef WANT_WIDE
  539. while (n && (*r1 == *r2)) {
  540. ++r1;
  541. ++r2;
  542. --n;
  543. }
  544. return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);
  545. #else
  546. int r = 0;
  547. while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0));
  548. return r;
  549. #endif
  550. }
  551. #endif
  552. /**********************************************************************/
  553. #ifdef L_wcscmp
  554. #define L_strcmp
  555. #define Wstrcmp wcscmp
  556. #else
  557. #define Wstrcmp strcmp
  558. #endif
  559. #ifdef L_strcmp
  560. #ifdef L_wcscmp
  561. #ifdef __UCLIBC_MJN3_ONLY__
  562. #warning implement wcscoll and remove weak alias (or enable for C locale only)
  563. #endif
  564. weak_alias(wcscmp,wcscoll);
  565. #else /* L_wcscmp */
  566. #ifdef __UCLIBC_MJN3_ONLY__
  567. #warning implement strcoll and remove weak alias (or enable for C locale only)
  568. #endif
  569. weak_alias(strcmp,strcoll);
  570. #endif /* L_wcscmp */
  571. int Wstrcmp(register const Wchar *s1, register const Wchar *s2)
  572. {
  573. #ifdef WANT_WIDE
  574. while (*((Wuchar *)s1) == *((Wuchar *)s2)) {
  575. if (!*s1++) {
  576. return 0;
  577. }
  578. ++s2;
  579. }
  580. return (*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1;
  581. #else
  582. int r;
  583. while (((r = ((int)(*((Wuchar *)s1))) - *((Wuchar *)s2++))
  584. == 0) && *s1++);
  585. return r;
  586. #endif
  587. }
  588. #endif
  589. /**********************************************************************/
  590. #ifdef L_strcoll
  591. #error implement strcoll and remove weak_alias!!
  592. #if 0
  593. extern unsigned char *_ctype_collate;
  594. int strcoll(register const char *s1, const char *s2)
  595. {
  596. int r;
  597. while (!(r = (_ctype_collate[(int)(*s1++)]-_ctype_collate[(int)(*s2++)])));
  598. return r;
  599. }
  600. #endif
  601. #endif
  602. /**********************************************************************/
  603. #ifdef L_wcsncmp
  604. #define L_strncmp
  605. #define Wstrncmp wcsncmp
  606. #else
  607. #define Wstrncmp strncmp
  608. #endif
  609. #ifdef L_strncmp
  610. int Wstrncmp(register const Wchar *s1, register const Wchar *s2, size_t n)
  611. {
  612. #ifdef WANT_WIDE
  613. while (n && (*((Wuchar *)s1) == *((Wuchar *)s2))) {
  614. if (!*s1++) {
  615. return 0;
  616. }
  617. ++s2;
  618. --n;
  619. }
  620. return (n == 0) ? 0 : ((*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1);
  621. #else
  622. int r = 0;
  623. while (n--
  624. && ((r = ((int)(*((unsigned char *)s1))) - *((unsigned char *)s2++))
  625. == 0)
  626. && *s1++);
  627. return r;
  628. #endif
  629. }
  630. #endif
  631. /**********************************************************************/
  632. #ifdef L_strxfrm
  633. #error implement strxfrm
  634. /* size_t strxfrm(char *dst, const char *src, size_t len); */
  635. #endif
  636. /**********************************************************************/
  637. #ifdef L_wmemchr
  638. #define L_memchr
  639. #define Wmemchr wmemchr
  640. #else
  641. #define Wmemchr memchr
  642. #endif
  643. #ifdef L_memchr
  644. Wvoid *Wmemchr(const Wvoid *s, Wint c, size_t n)
  645. {
  646. register const Wuchar *r = (const Wuchar *) s;
  647. #ifdef __BCC__
  648. /* bcc can optimize the counter if it thinks it is a pointer... */
  649. register const char *np = (const char *) n;
  650. #else
  651. #define np n
  652. #endif
  653. while (np) {
  654. if (*r == ((Wuchar)c)) {
  655. return (Wvoid *) r; /* silence the warning */
  656. }
  657. ++r;
  658. --np;
  659. }
  660. return NULL;
  661. }
  662. #undef np
  663. #endif
  664. /**********************************************************************/
  665. #ifdef L_wcschr
  666. #define L_strchr
  667. #define Wstrchr wcschr
  668. #else
  669. #define Wstrchr strchr
  670. #endif
  671. #ifdef L_strchr
  672. #ifndef L_wcschr
  673. weak_alias(strchr,index);
  674. #endif
  675. Wchar *Wstrchr(register const Wchar *s, Wint c)
  676. {
  677. do {
  678. if (*s == ((Wchar)c)) {
  679. return (Wchar *) s; /* silence the warning */
  680. }
  681. } while (*s++);
  682. return NULL;
  683. }
  684. #endif
  685. /**********************************************************************/
  686. #ifdef L_wcscspn
  687. #define L_strcspn
  688. #define Wstrcspn wcscspn
  689. #else
  690. #define Wstrcspn strcspn
  691. #endif
  692. #ifdef L_strcspn
  693. size_t Wstrcspn(const Wchar *s1, const Wchar *s2)
  694. {
  695. register const Wchar *s;
  696. register const Wchar *p;
  697. for ( s=s1 ; *s ; s++ ) {
  698. for ( p=s2 ; *p ; p++ ) {
  699. if (*p == *s) goto done;
  700. }
  701. }
  702. done:
  703. return s - s1;
  704. }
  705. #endif
  706. /**********************************************************************/
  707. #ifdef L_wcspbrk
  708. #define L_strpbrk
  709. #define Wstrpbrk wcspbrk
  710. #else
  711. #define Wstrpbrk strpbrk
  712. #endif
  713. #ifdef L_strpbrk
  714. Wchar *Wstrpbrk(const Wchar *s1, const Wchar *s2)
  715. {
  716. register const Wchar *s;
  717. register const Wchar *p;
  718. for ( s=s1 ; *s ; s++ ) {
  719. for ( p=s2 ; *p ; p++ ) {
  720. if (*p == *s) return (Wchar *) s; /* silence the warning */
  721. }
  722. }
  723. return NULL;
  724. }
  725. #endif
  726. /**********************************************************************/
  727. #ifdef L_wcsrchr
  728. #define L_strrchr
  729. #define Wstrrchr wcsrchr
  730. #else
  731. #define Wstrrchr strrchr
  732. #endif
  733. #ifdef L_strrchr
  734. #ifndef L_wcsrchr
  735. weak_alias(strrchr,rindex);
  736. #endif
  737. Wchar *Wstrrchr(register const Wchar *s, Wint c)
  738. {
  739. register const Wchar *p;
  740. p = NULL;
  741. do {
  742. if (*s == (Wchar) c) {
  743. p = s;
  744. }
  745. } while (*s++);
  746. return (Wchar *) p; /* silence the warning */
  747. }
  748. #endif
  749. /**********************************************************************/
  750. #ifdef L_wcsspn
  751. #define L_strspn
  752. #define Wstrspn wcsspn
  753. #else
  754. #define Wstrspn strspn
  755. #endif
  756. #ifdef L_strspn
  757. size_t Wstrspn(const Wchar *s1, const Wchar *s2)
  758. {
  759. register const Wchar *s = s1;
  760. register const Wchar *p = s2;
  761. while (*p) {
  762. if (*p++ == *s) {
  763. ++s;
  764. p = s2;
  765. }
  766. }
  767. return s - s1;
  768. }
  769. #endif
  770. /**********************************************************************/
  771. #ifdef L_wcsstr
  772. #define L_strstr
  773. #define Wstrstr wcsstr
  774. #else
  775. #define Wstrstr strstr
  776. #endif
  777. #ifdef L_strstr
  778. /* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
  779. #ifdef L_wcsstr
  780. weak_alias(wcsstr,wcswcs);
  781. #endif
  782. Wchar *Wstrstr(const Wchar *s1, const Wchar *s2)
  783. {
  784. register const Wchar *s = s1;
  785. register const Wchar *p = s2;
  786. do {
  787. if (!*p) {
  788. return (Wchar *) s1;;
  789. }
  790. if (*p == *s) {
  791. ++p;
  792. ++s;
  793. } else {
  794. p = s2;
  795. if (!*s) {
  796. return NULL;
  797. }
  798. s = ++s1;
  799. }
  800. } while (1);
  801. }
  802. #endif
  803. /**********************************************************************/
  804. #undef Wstrspn
  805. #undef Wstrpbrk
  806. #ifdef L_wcstok
  807. #define L_strtok_r
  808. #define Wstrtok_r wcstok
  809. #define Wstrspn wcsspn
  810. #define Wstrpbrk wcspbrk
  811. #else
  812. #define Wstrtok_r strtok_r
  813. #define Wstrspn strspn
  814. #define Wstrpbrk strpbrk
  815. #endif
  816. #ifdef L_strtok_r
  817. Wchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
  818. Wchar ** __restrict next_start)
  819. {
  820. register Wchar *s;
  821. register Wchar *p;
  822. #if 1
  823. if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
  824. if (*(s += Wstrspn(s, s2))) {
  825. if ((p = Wstrpbrk(s, s2)) != NULL) {
  826. *p++ = 0;
  827. }
  828. } else {
  829. p = s = NULL;
  830. }
  831. *next_start = p;
  832. }
  833. return s;
  834. #else
  835. if (!(s = s1)) {
  836. s = *next_start;
  837. }
  838. if (s && *(s += Wstrspn(s, s2))) {
  839. if (*(p = s + Wstrcspn(s, s2))) {
  840. *p++ = 0;
  841. }
  842. *next_start = p;
  843. return s;
  844. }
  845. return NULL; /* TODO: set *next_start = NULL for safety? */
  846. #endif
  847. }
  848. #endif
  849. /**********************************************************************/
  850. /* #ifdef L_wcstok */
  851. /* #define L_strtok */
  852. /* #define Wstrtok wcstok */
  853. /* #define Wstrtok_r wcstok_r */
  854. /* #else */
  855. /* #define Wstrtok strtok */
  856. /* #define Wstrtok_r strtok_r */
  857. /* #endif */
  858. #ifdef L_strtok
  859. #define Wstrtok strtok
  860. #define Wstrtok_r strtok_r
  861. Wchar *Wstrtok(Wchar * __restrict s1, const Wchar * __restrict s2)
  862. {
  863. static Wchar *next_start; /* Initialized to 0 since in bss. */
  864. return Wstrtok_r(s1, s2, &next_start);
  865. }
  866. #endif
  867. /**********************************************************************/
  868. #ifdef L_wmemset
  869. #define L_memset
  870. #define Wmemset wmemset
  871. #else
  872. #define Wmemset memset
  873. #endif
  874. #ifdef L_memset
  875. Wvoid *Wmemset(Wvoid *s, Wint c, size_t n)
  876. {
  877. register Wuchar *p = (Wuchar *) s;
  878. #ifdef __BCC__
  879. /* bcc can optimize the counter if it thinks it is a pointer... */
  880. register const char *np = (const char *) n;
  881. #else
  882. #define np n
  883. #endif
  884. while (np) {
  885. *p++ = (Wuchar) c;
  886. --np;
  887. }
  888. return s;
  889. }
  890. #undef np
  891. #endif
  892. /**********************************************************************/
  893. #ifdef L_wcslen
  894. #define L_strlen
  895. #define Wstrlen wcslen
  896. #else
  897. #define Wstrlen strlen
  898. #endif
  899. #ifdef L_strlen
  900. size_t Wstrlen(const Wchar *s)
  901. {
  902. register const Wchar *p;
  903. for (p=s ; *p ; p++);
  904. return p - s;
  905. }
  906. #endif
  907. /**********************************************************************/
  908. /* ANSI/ISO end here */
  909. /**********************************************************************/
  910. #ifdef L_ffs
  911. int ffs(int i)
  912. {
  913. #if 1
  914. /* inlined binary search method */
  915. char n = 1;
  916. #if UINT_MAX == 0xffffU
  917. /* nothing to do here -- just trying to avoiding possible problems */
  918. #elif UINT_MAX == 0xffffffffU
  919. if (!(i & 0xffff)) {
  920. n += 16;
  921. i >>= 16;
  922. }
  923. #else
  924. #error ffs needs rewriting!
  925. #endif
  926. if (!(i & 0xff)) {
  927. n += 8;
  928. i >>= 8;
  929. }
  930. if (!(i & 0x0f)) {
  931. n += 4;
  932. i >>= 4;
  933. }
  934. if (!(i & 0x03)) {
  935. n += 2;
  936. i >>= 2;
  937. }
  938. return (i) ? (n + ((i+1) & 0x01)) : 0;
  939. #else
  940. /* linear search -- slow, but small */
  941. int n;
  942. for (n = 0 ; i ; ++n) {
  943. i >>= 1;
  944. }
  945. return n;
  946. #endif
  947. }
  948. #endif
  949. /**********************************************************************/
  950. #ifdef L_wcscasecmp
  951. #define L_strcasecmp
  952. #define Wstrcasecmp wcscasecmp
  953. #else
  954. #define Wstrcasecmp strcasecmp
  955. #endif
  956. #ifdef L_strcasecmp
  957. int Wstrcasecmp(register const Wchar *s1, register const Wchar *s2)
  958. {
  959. #ifdef WANT_WIDE
  960. while ((*s1 == *s2) || (towlower(*s1) == towlower(*s2))) {
  961. if (!*s1++) {
  962. return 0;
  963. }
  964. ++s2;
  965. }
  966. return (((Wuchar)towlower(*s1)) < ((Wuchar)towlower(*s2))) ? -1 : 1;
  967. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  968. #else
  969. int r = 0;
  970. while ( ((s1 == s2) ||
  971. !(r = ((int)( tolower(*((Wuchar *)s1))))
  972. - tolower(*((Wuchar *)s2))))
  973. && (++s2, *s1++));
  974. return r;
  975. #endif
  976. }
  977. #endif
  978. /**********************************************************************/
  979. #ifdef L_wcsncasecmp
  980. #define L_strncasecmp
  981. #define Wstrncasecmp wcsncasecmp
  982. #else
  983. #define Wstrncasecmp strncasecmp
  984. #endif
  985. #ifdef L_strncasecmp
  986. int Wstrncasecmp(register const Wchar *s1, register const Wchar *s2, size_t n)
  987. {
  988. #ifdef WANT_WIDE
  989. while (n && ((*s1 == *s2) || (towlower(*s1) == towlower(*s2)))) {
  990. if (!*s1++) {
  991. return 0;
  992. }
  993. ++s2;
  994. --n;
  995. }
  996. return (n == 0)
  997. ? 0
  998. : ((((Wuchar)towlower(*s1)) < ((Wuchar)towlower(*s2))) ? -1 : 1);
  999. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  1000. #else
  1001. int r = 0;
  1002. while ( n
  1003. && ((s1 == s2) ||
  1004. !(r = ((int)( tolower(*((unsigned char *)s1))))
  1005. - tolower(*((unsigned char *)s2))))
  1006. && (--n, ++s2, *s1++));
  1007. return r;
  1008. #endif
  1009. }
  1010. #endif
  1011. /**********************************************************************/
  1012. #ifdef L_wcsnlen
  1013. #define L_strnlen
  1014. #define Wstrnlen wcsnlen
  1015. #else
  1016. #define Wstrnlen strnlen
  1017. #endif
  1018. #ifdef L_strnlen
  1019. size_t Wstrnlen(const Wchar *s, size_t max)
  1020. {
  1021. register const Wchar *p = s;
  1022. #ifdef __BCC__
  1023. /* bcc can optimize the counter if it thinks it is a pointer... */
  1024. register const char *maxp = (const char *) max;
  1025. #else
  1026. #define maxp max
  1027. #endif
  1028. while (maxp && *p) {
  1029. ++p;
  1030. --maxp;
  1031. }
  1032. return p - s;
  1033. }
  1034. #undef maxp
  1035. #endif
  1036. /**********************************************************************/
  1037. /* No wide analog. */
  1038. #ifdef L_memccpy
  1039. void *memccpy(void * __restrict s1, const void * __restrict s2, int c, size_t n)
  1040. {
  1041. register char *r1 = s1;
  1042. register const char *r2 = s2;
  1043. while (n-- && (((unsigned char)(*r1++ = *r2++)) != ((unsigned char) c)));
  1044. return (n == (size_t) -1) ? NULL : r1;
  1045. }
  1046. #endif
  1047. /**********************************************************************/
  1048. #undef Wstrlen
  1049. #undef Wstrcpy
  1050. #ifdef L_wcsdup
  1051. #define L_strdup
  1052. #define Wstrdup wcsdup
  1053. #define Wstrlen wcslen
  1054. #define Wstrcpy wcscpy
  1055. #else
  1056. #define Wstrdup strdup
  1057. #define Wstrlen strlen
  1058. #define Wstrcpy strcpy
  1059. #endif
  1060. #ifdef L_strdup
  1061. Wchar *Wstrdup(register const Wchar *s1)
  1062. {
  1063. register Wchar *s;
  1064. if ((s = malloc((Wstrlen(s1) + 1) * sizeof(Wchar))) != NULL) {
  1065. Wstrcpy(s, s1);
  1066. }
  1067. return s;
  1068. }
  1069. #endif
  1070. /**********************************************************************/
  1071. #ifdef L_strerror
  1072. char *strerror(int errnum)
  1073. {
  1074. static char buf[_SYS_ERRMSG_MAXLEN];
  1075. _susv3_strerror_r(errnum, buf, sizeof(buf));
  1076. return buf;
  1077. }
  1078. #endif
  1079. /**********************************************************************/
  1080. /* SUSv3 functions. */
  1081. /**********************************************************************/
  1082. #ifdef L__susv3_strerror_r
  1083. #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
  1084. static const unsigned char estridx[] = {
  1085. 0, /* success is always 0 */
  1086. EPERM,
  1087. ENOENT,
  1088. ESRCH,
  1089. EINTR,
  1090. EIO,
  1091. ENXIO,
  1092. E2BIG,
  1093. ENOEXEC,
  1094. EBADF,
  1095. ECHILD,
  1096. EAGAIN,
  1097. ENOMEM,
  1098. EACCES,
  1099. EFAULT,
  1100. ENOTBLK,
  1101. EBUSY,
  1102. EEXIST,
  1103. EXDEV,
  1104. ENODEV,
  1105. ENOTDIR,
  1106. EISDIR,
  1107. EINVAL,
  1108. ENFILE,
  1109. EMFILE,
  1110. ENOTTY,
  1111. ETXTBSY,
  1112. EFBIG,
  1113. ENOSPC,
  1114. ESPIPE,
  1115. EROFS,
  1116. EMLINK,
  1117. EPIPE,
  1118. EDOM,
  1119. ERANGE,
  1120. EDEADLK,
  1121. ENAMETOOLONG,
  1122. ENOLCK,
  1123. ENOSYS,
  1124. ENOTEMPTY,
  1125. ELOOP,
  1126. 0,
  1127. ENOMSG,
  1128. EIDRM,
  1129. ECHRNG,
  1130. EL2NSYNC,
  1131. EL3HLT,
  1132. EL3RST,
  1133. ELNRNG,
  1134. EUNATCH,
  1135. ENOCSI,
  1136. EL2HLT,
  1137. EBADE,
  1138. EBADR,
  1139. EXFULL,
  1140. ENOANO,
  1141. EBADRQC,
  1142. EBADSLT,
  1143. 0,
  1144. EBFONT,
  1145. ENOSTR,
  1146. ENODATA,
  1147. ETIME,
  1148. ENOSR,
  1149. ENONET,
  1150. ENOPKG,
  1151. EREMOTE,
  1152. ENOLINK,
  1153. EADV,
  1154. ESRMNT,
  1155. ECOMM,
  1156. EPROTO,
  1157. EMULTIHOP,
  1158. EDOTDOT,
  1159. EBADMSG,
  1160. EOVERFLOW,
  1161. ENOTUNIQ,
  1162. EBADFD,
  1163. EREMCHG,
  1164. ELIBACC,
  1165. ELIBBAD,
  1166. ELIBSCN,
  1167. ELIBMAX,
  1168. ELIBEXEC,
  1169. EILSEQ,
  1170. ERESTART,
  1171. ESTRPIPE,
  1172. EUSERS,
  1173. ENOTSOCK,
  1174. EDESTADDRREQ,
  1175. EMSGSIZE,
  1176. EPROTOTYPE,
  1177. ENOPROTOOPT,
  1178. EPROTONOSUPPORT,
  1179. ESOCKTNOSUPPORT,
  1180. EOPNOTSUPP,
  1181. EPFNOSUPPORT,
  1182. EAFNOSUPPORT,
  1183. EADDRINUSE,
  1184. EADDRNOTAVAIL,
  1185. ENETDOWN,
  1186. ENETUNREACH,
  1187. ENETRESET,
  1188. ECONNABORTED,
  1189. ECONNRESET,
  1190. ENOBUFS,
  1191. EISCONN,
  1192. ENOTCONN,
  1193. ESHUTDOWN,
  1194. ETOOMANYREFS,
  1195. ETIMEDOUT,
  1196. ECONNREFUSED,
  1197. EHOSTDOWN,
  1198. EHOSTUNREACH,
  1199. EALREADY,
  1200. EINPROGRESS,
  1201. ESTALE,
  1202. EUCLEAN,
  1203. ENOTNAM,
  1204. ENAVAIL,
  1205. EISNAM,
  1206. EREMOTEIO,
  1207. #ifdef __mips__
  1208. 0, /* mips has an outrageous value for this... */
  1209. #else
  1210. EDQUOT,
  1211. #endif
  1212. ENOMEDIUM,
  1213. EMEDIUMTYPE,
  1214. #if defined(__mips__) || defined(__sparc__)
  1215. EDEADLOCK,
  1216. #endif
  1217. };
  1218. #endif
  1219. int _susv3_strerror_r(int errnum, char *strerrbuf, size_t buflen)
  1220. {
  1221. register char *s;
  1222. int i, retval;
  1223. char buf[_SYS_ERRMSG_MAXLEN];
  1224. static const char unknown[14] = {
  1225. 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
  1226. };
  1227. retval = EINVAL;
  1228. #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
  1229. /* Need to translate errno to string index. */
  1230. for (i = 0 ; i < sizeof(estridx)/sizeof(estridx[0]) ; i++) {
  1231. if (estridx[i] == errnum) {
  1232. goto GOT_ESTRIDX;
  1233. }
  1234. }
  1235. i = INT_MAX; /* Failed, but may need to check mips special case. */
  1236. #ifdef __mips__
  1237. if (errnum == EDQUOT) { /* Deal with large EDQUOT value on mips */
  1238. i = 122;
  1239. }
  1240. #endif /* __mips__ */
  1241. GOT_ESTRIDX:
  1242. #else
  1243. /* No errno to string index translation needed. */
  1244. i = errnum;
  1245. #endif
  1246. if (((unsigned int) i) < _SYS_NERR) {
  1247. /* Trade time for space. This function should rarely be called
  1248. * so rather than keeping an array of pointers for the different
  1249. * messages, just run through the buffer until we find the
  1250. * correct string. */
  1251. for (s = (char *) _string_syserrmsgs ; i ; ++s) {
  1252. if (!*s) {
  1253. --i;
  1254. }
  1255. }
  1256. if (*s) { /* Make sure we have an actual message. */
  1257. retval = 0;
  1258. goto GOT_MESG;
  1259. }
  1260. }
  1261. s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
  1262. memcpy(s, unknown, sizeof(unknown));
  1263. GOT_MESG:
  1264. if (!strerrbuf) { /* SUSv3 */
  1265. buflen = 0;
  1266. }
  1267. i = strlen(s) + 1;
  1268. if (i > buflen) {
  1269. i = buflen;
  1270. retval = ERANGE;
  1271. }
  1272. if (i) {
  1273. memcpy(strerrbuf, s, i);
  1274. strerrbuf[i-1] = 0; /* In case buf was too small. */
  1275. }
  1276. if (retval) {
  1277. __set_errno(retval);
  1278. }
  1279. return retval;
  1280. }
  1281. #endif
  1282. /**********************************************************************/
  1283. /* GNU extension functions. */
  1284. /**********************************************************************/
  1285. #ifdef L__glibc_strerror_r
  1286. weak_alias(_glibc_strerror_r,__strerror_r);
  1287. char *_glibc_strerror_r(int errnum, char *strerrbuf, size_t buflen)
  1288. {
  1289. _susv3_strerror_r(errnum, strerrbuf, buflen);
  1290. return strerrbuf;
  1291. }
  1292. #endif
  1293. /**********************************************************************/
  1294. #ifdef L_wmempcpy
  1295. #define L_mempcpy
  1296. #define Wmempcpy wmempcpy
  1297. #else
  1298. #define Wmempcpy mempcpy
  1299. #endif
  1300. #ifdef L_mempcpy
  1301. #ifndef L_wmempcpy
  1302. /* uClibc's old string implementation did this to cater to some app. */
  1303. weak_alias(mempcpy,__mempcpy);
  1304. #endif
  1305. Wvoid *Wmempcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
  1306. {
  1307. register Wchar *r1 = s1;
  1308. register const Wchar *r2 = s2;
  1309. #ifdef __BCC__
  1310. while (n--) {
  1311. *r1++ = *r2++;
  1312. }
  1313. #else
  1314. while (n) {
  1315. *r1++ = *r2++;
  1316. --n;
  1317. }
  1318. #endif
  1319. return r1;
  1320. }
  1321. #endif
  1322. /**********************************************************************/
  1323. #ifdef L_memrchr
  1324. void *memrchr(const void *s, int c, size_t n)
  1325. {
  1326. register const unsigned char *r;
  1327. #ifdef __BCC__
  1328. /* bcc can optimize the counter if it thinks it is a pointer... */
  1329. register const char *np = (const char *) n;
  1330. #else
  1331. #define np n
  1332. #endif
  1333. r = ((unsigned char *)s) + ((size_t) np);
  1334. while (np) {
  1335. if (*--r == ((unsigned char)c)) {
  1336. return (void *) r; /* silence the warning */
  1337. }
  1338. --np;
  1339. }
  1340. return NULL;
  1341. }
  1342. #undef np
  1343. #endif
  1344. /**********************************************************************/
  1345. #ifdef L_wcpcpy
  1346. #define L_stpcpy
  1347. #define Wstpcpy wcpcpy
  1348. #else
  1349. #define Wstpcpy stpcpy
  1350. #endif
  1351. #ifdef L_stpcpy
  1352. Wchar *Wstpcpy(register Wchar * __restrict s1, const Wchar * __restrict s2)
  1353. {
  1354. #ifdef __BCC__
  1355. do {
  1356. *s1 = *s2++;
  1357. } while (*s1++ != 0);
  1358. #else
  1359. while ( (*s1++ = *s2++) != 0 );
  1360. #endif
  1361. return s1 - 1;
  1362. }
  1363. #endif
  1364. /**********************************************************************/
  1365. #ifdef L_wcpncpy
  1366. #define L_stpncpy
  1367. #define Wstpncpy wcpncpy
  1368. #else
  1369. #define Wstpncpy stpncpy
  1370. #endif
  1371. #ifdef L_stpncpy
  1372. Wchar *Wstpncpy(register Wchar * __restrict s1,
  1373. register const Wchar * __restrict s2,
  1374. size_t n)
  1375. {
  1376. Wchar *s = s1;
  1377. const Wchar *p = s2;
  1378. #ifdef __BCC__
  1379. while (n--) {
  1380. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  1381. ++s;
  1382. }
  1383. return s1 + (s2 - p);
  1384. #else
  1385. while (n) {
  1386. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  1387. ++s;
  1388. --n;
  1389. }
  1390. return s1 + (s2 - p);
  1391. #endif
  1392. }
  1393. #endif
  1394. /**********************************************************************/
  1395. #ifdef L_bzero
  1396. void bzero(void *s, size_t n)
  1397. {
  1398. register unsigned char *p = s;
  1399. #ifdef __BCC__
  1400. /* bcc can optimize the counter if it thinks it is a pointer... */
  1401. register const char *np = (const char *) n;
  1402. #else
  1403. #define np n
  1404. #endif
  1405. while (np) {
  1406. *p++ = 0;
  1407. --np;
  1408. }
  1409. }
  1410. #undef np
  1411. #endif
  1412. /**********************************************************************/
  1413. #ifdef L_bcopy
  1414. void bcopy(const void *s2, void *s1, size_t n)
  1415. {
  1416. #if 1
  1417. memmove(s1, s2, n);
  1418. #else
  1419. #ifdef __BCC__
  1420. register char *s;
  1421. register const char *p;
  1422. s = s1;
  1423. p = s2;
  1424. if (p >= s) {
  1425. while (n--) {
  1426. *s++ = *p++;
  1427. }
  1428. } else {
  1429. s += n;
  1430. p += n;
  1431. while (n--) {
  1432. *--s = *--p;
  1433. }
  1434. }
  1435. #else
  1436. register char *s;
  1437. register const char *p;
  1438. s = s1;
  1439. p = s2;
  1440. if (p >= s) {
  1441. while (n) {
  1442. *s++ = *p++;
  1443. --n;
  1444. }
  1445. } else {
  1446. while (n) {
  1447. --n;
  1448. s[n] = p[n];
  1449. }
  1450. }
  1451. #endif
  1452. #endif
  1453. }
  1454. #endif
  1455. /**********************************************************************/
  1456. #ifdef L_strcasestr
  1457. char *strcasestr(const char *s1, const char *s2)
  1458. {
  1459. register const char *s = s1;
  1460. register const char *p = s2;
  1461. #if 1
  1462. do {
  1463. if (!*p) {
  1464. return (char *) s1;;
  1465. }
  1466. if ((*p == *s)
  1467. || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
  1468. ) {
  1469. ++p;
  1470. ++s;
  1471. } else {
  1472. p = s2;
  1473. if (!*s) {
  1474. return NULL;
  1475. }
  1476. s = ++s1;
  1477. }
  1478. } while (1);
  1479. #else
  1480. while (*p && *s) {
  1481. if ((*p == *s)
  1482. || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
  1483. ) {
  1484. ++p;
  1485. ++s;
  1486. } else {
  1487. p = s2;
  1488. s = ++s1;
  1489. }
  1490. }
  1491. return (*p) ? NULL : (char *) s1;
  1492. #endif
  1493. }
  1494. #endif
  1495. /**********************************************************************/
  1496. #ifdef L_strndup
  1497. char *strndup(register const char *s1, size_t n)
  1498. {
  1499. register char *s;
  1500. n = strnlen(s1,n); /* Avoid problems if s1 not nul-terminated. */
  1501. if ((s = malloc(n + 1)) != NULL) {
  1502. memcpy(s, s1, n);
  1503. s[n] = 0;
  1504. }
  1505. return s;
  1506. }
  1507. #endif
  1508. /**********************************************************************/
  1509. #ifdef L_strsep
  1510. char *strsep(char ** __restrict s1, const char * __restrict s2)
  1511. {
  1512. register char *s = *s1;
  1513. register char *p;
  1514. #if 1
  1515. p = NULL;
  1516. if (s && *s && (p = strpbrk(s, s2))) {
  1517. *p++ = 0;
  1518. }
  1519. #else
  1520. if (s && *s && *(p = s + strcspn(s, s2))) {
  1521. *p++ = 0;
  1522. } else {
  1523. p = NULL;
  1524. }
  1525. #endif
  1526. *s1 = p;
  1527. return s;
  1528. }
  1529. #endif
  1530. /**********************************************************************/
  1531. #ifdef L_wcschrnul
  1532. #define L_strchrnul
  1533. #define __Wstrchrnul __wcschrnul
  1534. #define Wstrchrnul wcschrnul
  1535. #else
  1536. #define __Wstrchrnul __strchrnul
  1537. #define Wstrchrnul strchrnul
  1538. #endif
  1539. #ifdef L_strchrnul
  1540. extern Wchar *__Wstrchrnul(register const Wchar *s, Wint c);
  1541. weak_alias(__Wstrchrnul, Wstrchrnul);
  1542. Wchar *__Wstrchrnul(register const Wchar *s, Wint c)
  1543. {
  1544. --s;
  1545. while (*++s && (*s != ((Wchar)c)));
  1546. return (Wchar *) s;
  1547. }
  1548. #endif
  1549. /**********************************************************************/
  1550. #ifdef L_rawmemchr
  1551. void *rawmemchr(const void *s, int c)
  1552. {
  1553. register const unsigned char *r = s;
  1554. while (*r != ((unsigned char)c)) ++r;
  1555. return (void *) r; /* silence the warning */
  1556. }
  1557. #endif
  1558. /**********************************************************************/
  1559. #ifdef L_basename
  1560. char *basename(const char *path)
  1561. {
  1562. register const char *s;
  1563. register const char *p;
  1564. p = s = path;
  1565. while (*s) {
  1566. if (*s++ == '/') {
  1567. p = s;
  1568. }
  1569. }
  1570. return (char *) p;
  1571. }
  1572. #endif
  1573. /**********************************************************************/
  1574. #ifdef L___xpg_basename
  1575. char *__xpg_basename(register char *path)
  1576. {
  1577. static const char null_or_empty[] = ".";
  1578. char *first;
  1579. register char *last;
  1580. first = (char *) null_or_empty;
  1581. if (path && *path) {
  1582. first = path;
  1583. last = path - 1;
  1584. do {
  1585. if ((*path != '/') && (path > ++last)) {
  1586. last = first = path;
  1587. }
  1588. } while (*++path);
  1589. if (*first == '/') {
  1590. last = first;
  1591. }
  1592. last[1] = 0;
  1593. }
  1594. return first;
  1595. }
  1596. #endif
  1597. /**********************************************************************/
  1598. #ifdef L_dirname
  1599. char *dirname(char *path)
  1600. {
  1601. static const char null_or_empty_or_noslash[] = ".";
  1602. register char *s;
  1603. register char *last;
  1604. char *first;
  1605. last = s = path;
  1606. if (s != NULL) {
  1607. LOOP:
  1608. while (*s && (*s != '/')) ++s;
  1609. first = s;
  1610. while (*s == '/') ++s;
  1611. if (*s) {
  1612. last = first;
  1613. goto LOOP;
  1614. }
  1615. if (last == path) {
  1616. if (*last != '/') {
  1617. goto DOT;
  1618. }
  1619. if ((*++last == '/') && (last[1] == 0)) {
  1620. ++last;
  1621. }
  1622. }
  1623. *last = 0;
  1624. return path;
  1625. }
  1626. DOT:
  1627. return (char *) null_or_empty_or_noslash;
  1628. }
  1629. #endif
  1630. /**********************************************************************/
  1631. #ifdef L_strlcat
  1632. /* OpenBSD function:
  1633. * Append at most n-1-strlen(dst) chars from src to dst and nul-terminate dst.
  1634. * Returns strlen(src) + strlen({original} dst), so truncation occurred if the
  1635. * return val is >= n.
  1636. * Note: If dst doesn't contain a nul in the first n chars, strlen(dst) is
  1637. * taken as n. */
  1638. size_t strlcat(register char *__restrict dst,
  1639. register const char *__restrict src,
  1640. size_t n)
  1641. {
  1642. size_t len;
  1643. char dummy[1];
  1644. len = 0;
  1645. while (1) {
  1646. if (len >= n) {
  1647. dst = dummy;
  1648. break;
  1649. }
  1650. if (!*dst) {
  1651. break;
  1652. }
  1653. ++dst;
  1654. ++len;
  1655. }
  1656. while ((*dst = *src) != 0) {
  1657. if (++len < n) {
  1658. ++dst;
  1659. }
  1660. ++src;
  1661. }
  1662. return len;
  1663. }
  1664. #endif
  1665. /**********************************************************************/
  1666. #ifdef L_wcsxfrm
  1667. #define L_strlcpy
  1668. #define Wstrlcpy wcsxfrm
  1669. #endif
  1670. #ifdef L_strlcpy
  1671. #ifndef L_wcsxfrm
  1672. #define Wstrlcpy strlcpy
  1673. #ifdef __UCLIBC_MJN3_ONLY__
  1674. #warning implement wcscoll and remove weak alias (or enable for C locale only)
  1675. #endif
  1676. weak_alias(strlcpy,strxfrm);
  1677. #endif
  1678. /* OpenBSD function:
  1679. * Copy at most n-1 chars from src to dst and nul-terminate dst.
  1680. * Returns strlen(src), so truncation occurred if the return value is >= n. */
  1681. size_t Wstrlcpy(register Wchar *__restrict dst,
  1682. register const Wchar *__restrict src,
  1683. size_t n)
  1684. {
  1685. const Wchar *src0 = src;
  1686. Wchar dummy[1];
  1687. if (!n) {
  1688. dst = dummy;
  1689. } else {
  1690. --n;
  1691. }
  1692. while ((*dst = *src) != 0) {
  1693. if (n) {
  1694. --n;
  1695. ++dst;
  1696. }
  1697. ++src;
  1698. }
  1699. return src - src0;
  1700. }
  1701. #endif
  1702. /**********************************************************************/
  1703. #ifdef L__string_syssigmsgs
  1704. const char _string_syssigmsgs[] = {
  1705. /* 0: 0, 1 */ "\0"
  1706. /* 1: 1, 7 */ "Hangup\0"
  1707. /* 2: 8, 10 */ "Interrupt\0"
  1708. /* 3: 18, 5 */ "Quit\0"
  1709. /* 4: 23, 20 */ "Illegal instruction\0"
  1710. /* 5: 43, 22 */ "Trace/breakpoint trap\0"
  1711. /* 6: 65, 8 */ "Aborted\0"
  1712. /* 7: 73, 10 */ "Bus error\0"
  1713. /* 8: 83, 25 */ "Floating point exception\0"
  1714. /* 9: 108, 7 */ "Killed\0"
  1715. /* 10: 115, 22 */ "User defined signal 1\0"
  1716. /* 11: 137, 19 */ "Segmentation fault\0"
  1717. /* 12: 156, 22 */ "User defined signal 2\0"
  1718. /* 13: 178, 12 */ "Broken pipe\0"
  1719. /* 14: 190, 12 */ "Alarm clock\0"
  1720. /* 15: 202, 11 */ "Terminated\0"
  1721. /* 16: 213, 12 */ "Stack fault\0"
  1722. /* 17: 225, 13 */ "Child exited\0"
  1723. /* 18: 238, 10 */ "Continued\0"
  1724. /* 19: 248, 17 */ "Stopped (signal)\0"
  1725. /* 20: 265, 8 */ "Stopped\0"
  1726. /* 21: 273, 20 */ "Stopped (tty input)\0"
  1727. /* 22: 293, 21 */ "Stopped (tty output)\0"
  1728. /* 23: 314, 21 */ "Urgent I/O condition\0"
  1729. /* 24: 335, 24 */ "CPU time limit exceeded\0"
  1730. /* 25: 359, 25 */ "File size limit exceeded\0"
  1731. /* 26: 384, 22 */ "Virtual timer expired\0"
  1732. /* 27: 406, 24 */ "Profiling timer expired\0"
  1733. /* 28: 430, 15 */ "Window changed\0"
  1734. /* 29: 445, 13 */ "I/O possible\0"
  1735. /* 30: 458, 14 */ "Power failure\0"
  1736. /* 31: 472, 16 */ "Bad system call"
  1737. };
  1738. #endif
  1739. /**********************************************************************/
  1740. #ifdef L_sys_siglist
  1741. const char *const sys_siglist[_NSIG] = {
  1742. NULL,
  1743. _string_syssigmsgs + 1,
  1744. _string_syssigmsgs + 8,
  1745. _string_syssigmsgs + 18,
  1746. _string_syssigmsgs + 23,
  1747. _string_syssigmsgs + 43,
  1748. _string_syssigmsgs + 65,
  1749. _string_syssigmsgs + 73,
  1750. _string_syssigmsgs + 83,
  1751. _string_syssigmsgs + 108,
  1752. _string_syssigmsgs + 115,
  1753. _string_syssigmsgs + 137,
  1754. _string_syssigmsgs + 156,
  1755. _string_syssigmsgs + 178,
  1756. _string_syssigmsgs + 190,
  1757. _string_syssigmsgs + 202,
  1758. _string_syssigmsgs + 213,
  1759. _string_syssigmsgs + 225,
  1760. _string_syssigmsgs + 238,
  1761. _string_syssigmsgs + 248,
  1762. _string_syssigmsgs + 265,
  1763. _string_syssigmsgs + 273,
  1764. _string_syssigmsgs + 293,
  1765. _string_syssigmsgs + 314,
  1766. _string_syssigmsgs + 335,
  1767. _string_syssigmsgs + 359,
  1768. _string_syssigmsgs + 384,
  1769. _string_syssigmsgs + 406,
  1770. _string_syssigmsgs + 430,
  1771. _string_syssigmsgs + 445,
  1772. _string_syssigmsgs + 458,
  1773. _string_syssigmsgs + 472,
  1774. NULL,
  1775. NULL,
  1776. NULL,
  1777. NULL,
  1778. NULL,
  1779. NULL,
  1780. NULL,
  1781. NULL,
  1782. NULL,
  1783. NULL,
  1784. NULL,
  1785. NULL,
  1786. NULL,
  1787. NULL,
  1788. NULL,
  1789. NULL,
  1790. NULL,
  1791. NULL,
  1792. NULL,
  1793. NULL,
  1794. NULL,
  1795. NULL,
  1796. NULL,
  1797. NULL,
  1798. NULL,
  1799. NULL,
  1800. NULL,
  1801. NULL,
  1802. NULL,
  1803. NULL,
  1804. NULL,
  1805. NULL,
  1806. };
  1807. #endif
  1808. /**********************************************************************/
  1809. #ifdef L_strsignal
  1810. /* TODO: make a threadsafe version? */
  1811. char *strsignal(int signum)
  1812. {
  1813. register char *s;
  1814. int i;
  1815. static char buf[_STRSIGNAL_BUFSIZE];
  1816. static const char unknown[15] = {
  1817. 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' '
  1818. };
  1819. if (((unsigned int) signum) < _SYS_NSIG) {
  1820. /* Trade time for space. This function should rarely be called
  1821. * so rather than keeping an array of pointers for the different
  1822. * messages, just run through the buffer until we find the
  1823. * correct string. */
  1824. for (s = (char *) _string_syssigmsgs, i = signum ; i ; ++s) {
  1825. if (!*s) {
  1826. --i;
  1827. }
  1828. }
  1829. if (*s) { /* Make sure we have an actual message. */
  1830. goto DONE;
  1831. }
  1832. }
  1833. s = _int10tostr(buf+sizeof(buf)-1, signum) - sizeof(unknown);
  1834. memcpy(s, unknown, sizeof(unknown));
  1835. DONE:
  1836. return s;
  1837. }
  1838. #endif
  1839. /**********************************************************************/
  1840. #ifdef L_psignal
  1841. /* TODO: make this threadsafe with a reentrant version of strsignal? */
  1842. void psignal(int signum, register const char *message)
  1843. {
  1844. /* If the program is calling psignal, it's a safe bet that printf and
  1845. * friends are used as well. It is also possible that the calling
  1846. * program could buffer stderr, or reassign it. */
  1847. register const char *sep;
  1848. sep = ": ";
  1849. if (!(message && *message)) { /* Caller did not supply a prefix message */
  1850. message = (sep += 2); /* or passed an empty string. */
  1851. }
  1852. #if 1
  1853. fprintf(stderr, "%s%s%s\n", message, sep, strsignal(signum));
  1854. #else
  1855. /* Note: Assumes stderr not closed or buffered. */
  1856. __STDIO_THREADLOCK(stderr);
  1857. _stdio_fdout(STDERR_FILENO, message, sep, strsignal(signum));
  1858. __STDIO_THREADUNLOCK(stderr);
  1859. #endif
  1860. }
  1861. #endif
  1862. /**********************************************************************/