wstring.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129
  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. #ifndef L_wcscmp
  561. #ifdef __UCLIBC_MJN3_ONLY__
  562. #warning implement strcoll and remove weak alias (or enable for C locale only)
  563. #endif
  564. weak_alias(strcmp,strcoll);
  565. #endif
  566. int Wstrcmp(register const Wchar *s1, register const Wchar *s2)
  567. {
  568. #ifdef WANT_WIDE
  569. while (*((Wuchar *)s1) == *((Wuchar *)s2)) {
  570. if (!*s1++) {
  571. return 0;
  572. }
  573. ++s2;
  574. }
  575. return (*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1;
  576. #else
  577. int r;
  578. while (((r = ((int)(*((Wuchar *)s1))) - *((Wuchar *)s2++))
  579. == 0) && *s1++);
  580. return r;
  581. #endif
  582. }
  583. #endif
  584. /**********************************************************************/
  585. #ifdef L_strcoll
  586. #error implement strcoll and remove weak_alias!!
  587. #if 0
  588. extern unsigned char *_ctype_collate;
  589. int strcoll(register const char *s1, const char *s2)
  590. {
  591. int r;
  592. while (!(r = (_ctype_collate[(int)(*s1++)]-_ctype_collate[(int)(*s2++)])));
  593. return r;
  594. }
  595. #endif
  596. #endif
  597. /**********************************************************************/
  598. #ifdef L_wcsncmp
  599. #define L_strncmp
  600. #define Wstrncmp wcsncmp
  601. #else
  602. #define Wstrncmp strncmp
  603. #endif
  604. #ifdef L_strncmp
  605. int Wstrncmp(register const Wchar *s1, register const Wchar *s2, size_t n)
  606. {
  607. #ifdef WANT_WIDE
  608. while (n && (*((Wuchar *)s1) == *((Wuchar *)s2))) {
  609. if (!*s1++) {
  610. return 0;
  611. }
  612. ++s2;
  613. --n;
  614. }
  615. return (n == 0) ? 0 : ((*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1);
  616. #else
  617. int r = 0;
  618. while (n--
  619. && ((r = ((int)(*((unsigned char *)s1))) - *((unsigned char *)s2++))
  620. == 0)
  621. && *s1++);
  622. return r;
  623. #endif
  624. }
  625. #endif
  626. /**********************************************************************/
  627. #ifdef L_strxfrm
  628. #error implement strxfrm
  629. /* size_t strxfrm(char *dst, const char *src, size_t len); */
  630. #endif
  631. /**********************************************************************/
  632. #ifdef L_wmemchr
  633. #define L_memchr
  634. #define Wmemchr wmemchr
  635. #else
  636. #define Wmemchr memchr
  637. #endif
  638. #ifdef L_memchr
  639. Wvoid *Wmemchr(const Wvoid *s, Wint c, size_t n)
  640. {
  641. register const Wuchar *r = (const Wuchar *) s;
  642. #ifdef __BCC__
  643. /* bcc can optimize the counter if it thinks it is a pointer... */
  644. register const char *np = (const char *) n;
  645. #else
  646. #define np n
  647. #endif
  648. while (np) {
  649. if (*r == ((Wuchar)c)) {
  650. return (Wvoid *) r; /* silence the warning */
  651. }
  652. ++r;
  653. --np;
  654. }
  655. return NULL;
  656. }
  657. #undef np
  658. #endif
  659. /**********************************************************************/
  660. #ifdef L_wcschr
  661. #define L_strchr
  662. #define Wstrchr wcschr
  663. #else
  664. #define Wstrchr strchr
  665. #endif
  666. #ifdef L_strchr
  667. #ifndef L_wcschr
  668. weak_alias(strchr,index);
  669. #endif
  670. Wchar *Wstrchr(register const Wchar *s, Wint c)
  671. {
  672. do {
  673. if (*s == ((Wchar)c)) {
  674. return (Wchar *) s; /* silence the warning */
  675. }
  676. } while (*s++);
  677. return NULL;
  678. }
  679. #endif
  680. /**********************************************************************/
  681. #ifdef L_wcscspn
  682. #define L_strcspn
  683. #define Wstrcspn wcscspn
  684. #else
  685. #define Wstrcspn strcspn
  686. #endif
  687. #ifdef L_strcspn
  688. size_t Wstrcspn(const Wchar *s1, const Wchar *s2)
  689. {
  690. register const Wchar *s;
  691. register const Wchar *p;
  692. for ( s=s1 ; *s ; s++ ) {
  693. for ( p=s2 ; *p ; p++ ) {
  694. if (*p == *s) goto done;
  695. }
  696. }
  697. done:
  698. return s - s1;
  699. }
  700. #endif
  701. /**********************************************************************/
  702. #ifdef L_wcspbrk
  703. #define L_strpbrk
  704. #define Wstrpbrk wcspbrk
  705. #else
  706. #define Wstrpbrk strpbrk
  707. #endif
  708. #ifdef L_strpbrk
  709. Wchar *Wstrpbrk(const Wchar *s1, const Wchar *s2)
  710. {
  711. register const Wchar *s;
  712. register const Wchar *p;
  713. for ( s=s1 ; *s ; s++ ) {
  714. for ( p=s2 ; *p ; p++ ) {
  715. if (*p == *s) return (Wchar *) s; /* silence the warning */
  716. }
  717. }
  718. return NULL;
  719. }
  720. #endif
  721. /**********************************************************************/
  722. #ifdef L_wcsrchr
  723. #define L_strrchr
  724. #define Wstrrchr wcsrchr
  725. #else
  726. #define Wstrrchr strrchr
  727. #endif
  728. #ifdef L_strrchr
  729. #ifndef L_wcsrchr
  730. weak_alias(strrchr,rindex);
  731. #endif
  732. Wchar *Wstrrchr(register const Wchar *s, Wint c)
  733. {
  734. register const Wchar *p;
  735. p = NULL;
  736. do {
  737. if (*s == (Wchar) c) {
  738. p = s;
  739. }
  740. } while (*s++);
  741. return (Wchar *) p; /* silence the warning */
  742. }
  743. #endif
  744. /**********************************************************************/
  745. #ifdef L_wcsspn
  746. #define L_strspn
  747. #define Wstrspn wcsspn
  748. #else
  749. #define Wstrspn strspn
  750. #endif
  751. #ifdef L_strspn
  752. size_t Wstrspn(const Wchar *s1, const Wchar *s2)
  753. {
  754. register const Wchar *s = s1;
  755. register const Wchar *p = s2;
  756. while (*p) {
  757. if (*p++ == *s) {
  758. ++s;
  759. p = s2;
  760. }
  761. }
  762. return s - s1;
  763. }
  764. #endif
  765. /**********************************************************************/
  766. #ifdef L_wcsstr
  767. #define L_strstr
  768. #define Wstrstr wcsstr
  769. #else
  770. #define Wstrstr strstr
  771. #endif
  772. #ifdef L_strstr
  773. /* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
  774. #ifdef L_wcsstr
  775. weak_alias(wcsstr,wcswcs);
  776. #endif
  777. Wchar *Wstrstr(const Wchar *s1, const Wchar *s2)
  778. {
  779. register const Wchar *s = s1;
  780. register const Wchar *p = s2;
  781. do {
  782. if (!*p) {
  783. return (Wchar *) s1;;
  784. }
  785. if (*p == *s) {
  786. ++p;
  787. ++s;
  788. } else {
  789. p = s2;
  790. if (!*s) {
  791. return NULL;
  792. }
  793. s = ++s1;
  794. }
  795. } while (1);
  796. }
  797. #endif
  798. /**********************************************************************/
  799. #undef Wstrspn
  800. #undef Wstrpbrk
  801. #ifdef L_wcstok
  802. #define L_strtok_r
  803. #define Wstrtok_r wcstok
  804. #define Wstrspn wcsspn
  805. #define Wstrpbrk wcspbrk
  806. #else
  807. #define Wstrtok_r strtok_r
  808. #define Wstrspn strspn
  809. #define Wstrpbrk strpbrk
  810. #endif
  811. #ifdef L_strtok_r
  812. Wchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
  813. Wchar ** __restrict next_start)
  814. {
  815. register Wchar *s;
  816. register Wchar *p;
  817. #if 1
  818. if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
  819. if (*(s += Wstrspn(s, s2))) {
  820. if ((p = Wstrpbrk(s, s2)) != NULL) {
  821. *p++ = 0;
  822. }
  823. } else {
  824. p = s = NULL;
  825. }
  826. *next_start = p;
  827. }
  828. return s;
  829. #else
  830. if (!(s = s1)) {
  831. s = *next_start;
  832. }
  833. if (s && *(s += Wstrspn(s, s2))) {
  834. if (*(p = s + Wstrcspn(s, s2))) {
  835. *p++ = 0;
  836. }
  837. *next_start = p;
  838. return s;
  839. }
  840. return NULL; /* TODO: set *next_start = NULL for safety? */
  841. #endif
  842. }
  843. #endif
  844. /**********************************************************************/
  845. /* #ifdef L_wcstok */
  846. /* #define L_strtok */
  847. /* #define Wstrtok wcstok */
  848. /* #define Wstrtok_r wcstok_r */
  849. /* #else */
  850. /* #define Wstrtok strtok */
  851. /* #define Wstrtok_r strtok_r */
  852. /* #endif */
  853. #ifdef L_strtok
  854. #define Wstrtok strtok
  855. #define Wstrtok_r strtok_r
  856. Wchar *Wstrtok(Wchar * __restrict s1, const Wchar * __restrict s2)
  857. {
  858. static Wchar *next_start; /* Initialized to 0 since in bss. */
  859. return Wstrtok_r(s1, s2, &next_start);
  860. }
  861. #endif
  862. /**********************************************************************/
  863. #ifdef L_wmemset
  864. #define L_memset
  865. #define Wmemset wmemset
  866. #else
  867. #define Wmemset memset
  868. #endif
  869. #ifdef L_memset
  870. Wvoid *Wmemset(Wvoid *s, Wint c, size_t n)
  871. {
  872. register Wuchar *p = (Wuchar *) s;
  873. #ifdef __BCC__
  874. /* bcc can optimize the counter if it thinks it is a pointer... */
  875. register const char *np = (const char *) n;
  876. #else
  877. #define np n
  878. #endif
  879. while (np) {
  880. *p++ = (Wuchar) c;
  881. --np;
  882. }
  883. return s;
  884. }
  885. #undef np
  886. #endif
  887. /**********************************************************************/
  888. #ifdef L_wcslen
  889. #define L_strlen
  890. #define Wstrlen wcslen
  891. #else
  892. #define Wstrlen strlen
  893. #endif
  894. #ifdef L_strlen
  895. size_t Wstrlen(const Wchar *s)
  896. {
  897. register const Wchar *p;
  898. for (p=s ; *p ; p++);
  899. return p - s;
  900. }
  901. #endif
  902. /**********************************************************************/
  903. /* ANSI/ISO end here */
  904. /**********************************************************************/
  905. #ifdef L_ffs
  906. int ffs(int i)
  907. {
  908. #if 1
  909. /* inlined binary search method */
  910. char n = 1;
  911. #if UINT_MAX == 0xffffU
  912. /* nothing to do here -- just trying to avoiding possible problems */
  913. #elif UINT_MAX == 0xffffffffU
  914. if (!(i & 0xffff)) {
  915. n += 16;
  916. i >>= 16;
  917. }
  918. #else
  919. #error ffs needs rewriting!
  920. #endif
  921. if (!(i & 0xff)) {
  922. n += 8;
  923. i >>= 8;
  924. }
  925. if (!(i & 0x0f)) {
  926. n += 4;
  927. i >>= 4;
  928. }
  929. if (!(i & 0x03)) {
  930. n += 2;
  931. i >>= 2;
  932. }
  933. return (i) ? (n + ((i+1) & 0x01)) : 0;
  934. #else
  935. /* linear search -- slow, but small */
  936. int n;
  937. for (n = 0 ; i ; ++n) {
  938. i >>= 1;
  939. }
  940. return n;
  941. #endif
  942. }
  943. #endif
  944. /**********************************************************************/
  945. #ifdef L_wcscasecmp
  946. #define L_strcasecmp
  947. #define Wstrcasecmp wcscasecmp
  948. #else
  949. #define Wstrcasecmp strcasecmp
  950. #endif
  951. #ifdef L_strcasecmp
  952. int Wstrcasecmp(register const Wchar *s1, register const Wchar *s2)
  953. {
  954. #ifdef WANT_WIDE
  955. while ((*s1 == *s2) || (towlower(*s1) == towlower(*s2))) {
  956. if (!*s1++) {
  957. return 0;
  958. }
  959. ++s2;
  960. }
  961. return (((Wuchar)towlower(*s1)) < ((Wuchar)towlower(*s2))) ? -1 : 1;
  962. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  963. #else
  964. int r = 0;
  965. while ( ((s1 == s2) ||
  966. !(r = ((int)( tolower(*((Wuchar *)s1))))
  967. - tolower(*((Wuchar *)s2))))
  968. && (++s2, *s1++));
  969. return r;
  970. #endif
  971. }
  972. #endif
  973. /**********************************************************************/
  974. #ifdef L_wcsncasecmp
  975. #define L_strncasecmp
  976. #define Wstrncasecmp wcsncasecmp
  977. #else
  978. #define Wstrncasecmp strncasecmp
  979. #endif
  980. #ifdef L_strncasecmp
  981. int Wstrncasecmp(register const Wchar *s1, register const Wchar *s2, size_t n)
  982. {
  983. #ifdef WANT_WIDE
  984. while (n && ((*s1 == *s2) || (towlower(*s1) == towlower(*s2)))) {
  985. if (!*s1++) {
  986. return 0;
  987. }
  988. ++s2;
  989. --n;
  990. }
  991. return (n == 0)
  992. ? 0
  993. : ((((Wuchar)towlower(*s1)) < ((Wuchar)towlower(*s2))) ? -1 : 1);
  994. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  995. #else
  996. int r = 0;
  997. while ( n
  998. && ((s1 == s2) ||
  999. !(r = ((int)( tolower(*((unsigned char *)s1))))
  1000. - tolower(*((unsigned char *)s2))))
  1001. && (--n, ++s2, *s1++));
  1002. return r;
  1003. #endif
  1004. }
  1005. #endif
  1006. /**********************************************************************/
  1007. #ifdef L_wcsnlen
  1008. #define L_strnlen
  1009. #define Wstrnlen wcsnlen
  1010. #else
  1011. #define Wstrnlen strnlen
  1012. #endif
  1013. #ifdef L_strnlen
  1014. size_t Wstrnlen(const Wchar *s, size_t max)
  1015. {
  1016. register const Wchar *p = s;
  1017. #ifdef __BCC__
  1018. /* bcc can optimize the counter if it thinks it is a pointer... */
  1019. register const char *maxp = (const char *) max;
  1020. #else
  1021. #define maxp max
  1022. #endif
  1023. while (maxp && *p) {
  1024. ++p;
  1025. --maxp;
  1026. }
  1027. return p - s;
  1028. }
  1029. #undef maxp
  1030. #endif
  1031. /**********************************************************************/
  1032. /* No wide analog. */
  1033. #ifdef L_memccpy
  1034. void *memccpy(void * __restrict s1, const void * __restrict s2, int c, size_t n)
  1035. {
  1036. register char *r1 = s1;
  1037. register const char *r2 = s2;
  1038. while (n-- && (((unsigned char)(*r1++ = *r2++)) != ((unsigned char) c)));
  1039. return (n == (size_t) -1) ? NULL : r1;
  1040. }
  1041. #endif
  1042. /**********************************************************************/
  1043. #undef Wstrlen
  1044. #undef Wstrcpy
  1045. #ifdef L_wcsdup
  1046. #define L_strdup
  1047. #define Wstrdup wcsdup
  1048. #define Wstrlen wcslen
  1049. #define Wstrcpy wcscpy
  1050. #else
  1051. #define Wstrdup strdup
  1052. #define Wstrlen strlen
  1053. #define Wstrcpy strcpy
  1054. #endif
  1055. #ifdef L_strdup
  1056. Wchar *Wstrdup(register const Wchar *s1)
  1057. {
  1058. register Wchar *s;
  1059. if ((s = malloc((Wstrlen(s1) + 1) * sizeof(Wchar))) != NULL) {
  1060. Wstrcpy(s, s1);
  1061. }
  1062. return s;
  1063. }
  1064. #endif
  1065. /**********************************************************************/
  1066. #ifdef L_strerror
  1067. char *strerror(int errnum)
  1068. {
  1069. static char buf[_SYS_ERRMSG_MAXLEN];
  1070. _susv3_strerror_r(errnum, buf, sizeof(buf));
  1071. return buf;
  1072. }
  1073. #endif
  1074. /**********************************************************************/
  1075. /* SUSv3 functions. */
  1076. /**********************************************************************/
  1077. #ifdef L__susv3_strerror_r
  1078. #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
  1079. static const unsigned char estridx[] = {
  1080. 0, /* success is always 0 */
  1081. EPERM,
  1082. ENOENT,
  1083. ESRCH,
  1084. EINTR,
  1085. EIO,
  1086. ENXIO,
  1087. E2BIG,
  1088. ENOEXEC,
  1089. EBADF,
  1090. ECHILD,
  1091. EAGAIN,
  1092. ENOMEM,
  1093. EACCES,
  1094. EFAULT,
  1095. ENOTBLK,
  1096. EBUSY,
  1097. EEXIST,
  1098. EXDEV,
  1099. ENODEV,
  1100. ENOTDIR,
  1101. EISDIR,
  1102. EINVAL,
  1103. ENFILE,
  1104. EMFILE,
  1105. ENOTTY,
  1106. ETXTBSY,
  1107. EFBIG,
  1108. ENOSPC,
  1109. ESPIPE,
  1110. EROFS,
  1111. EMLINK,
  1112. EPIPE,
  1113. EDOM,
  1114. ERANGE,
  1115. EDEADLK,
  1116. ENAMETOOLONG,
  1117. ENOLCK,
  1118. ENOSYS,
  1119. ENOTEMPTY,
  1120. ELOOP,
  1121. 0,
  1122. ENOMSG,
  1123. EIDRM,
  1124. ECHRNG,
  1125. EL2NSYNC,
  1126. EL3HLT,
  1127. EL3RST,
  1128. ELNRNG,
  1129. EUNATCH,
  1130. ENOCSI,
  1131. EL2HLT,
  1132. EBADE,
  1133. EBADR,
  1134. EXFULL,
  1135. ENOANO,
  1136. EBADRQC,
  1137. EBADSLT,
  1138. 0,
  1139. EBFONT,
  1140. ENOSTR,
  1141. ENODATA,
  1142. ETIME,
  1143. ENOSR,
  1144. ENONET,
  1145. ENOPKG,
  1146. EREMOTE,
  1147. ENOLINK,
  1148. EADV,
  1149. ESRMNT,
  1150. ECOMM,
  1151. EPROTO,
  1152. EMULTIHOP,
  1153. EDOTDOT,
  1154. EBADMSG,
  1155. EOVERFLOW,
  1156. ENOTUNIQ,
  1157. EBADFD,
  1158. EREMCHG,
  1159. ELIBACC,
  1160. ELIBBAD,
  1161. ELIBSCN,
  1162. ELIBMAX,
  1163. ELIBEXEC,
  1164. EILSEQ,
  1165. ERESTART,
  1166. ESTRPIPE,
  1167. EUSERS,
  1168. ENOTSOCK,
  1169. EDESTADDRREQ,
  1170. EMSGSIZE,
  1171. EPROTOTYPE,
  1172. ENOPROTOOPT,
  1173. EPROTONOSUPPORT,
  1174. ESOCKTNOSUPPORT,
  1175. EOPNOTSUPP,
  1176. EPFNOSUPPORT,
  1177. EAFNOSUPPORT,
  1178. EADDRINUSE,
  1179. EADDRNOTAVAIL,
  1180. ENETDOWN,
  1181. ENETUNREACH,
  1182. ENETRESET,
  1183. ECONNABORTED,
  1184. ECONNRESET,
  1185. ENOBUFS,
  1186. EISCONN,
  1187. ENOTCONN,
  1188. ESHUTDOWN,
  1189. ETOOMANYREFS,
  1190. ETIMEDOUT,
  1191. ECONNREFUSED,
  1192. EHOSTDOWN,
  1193. EHOSTUNREACH,
  1194. EALREADY,
  1195. EINPROGRESS,
  1196. ESTALE,
  1197. EUCLEAN,
  1198. ENOTNAM,
  1199. ENAVAIL,
  1200. EISNAM,
  1201. EREMOTEIO,
  1202. #ifdef __mips__
  1203. 0, /* mips has an outrageous value for this... */
  1204. #else
  1205. EDQUOT,
  1206. #endif
  1207. ENOMEDIUM,
  1208. EMEDIUMTYPE,
  1209. #if defined(__mips__) || defined(__sparc__)
  1210. EDEADLOCK,
  1211. #endif
  1212. };
  1213. #endif
  1214. int _susv3_strerror_r(int errnum, char *strerrbuf, size_t buflen)
  1215. {
  1216. register char *s;
  1217. int i, retval;
  1218. char buf[_SYS_ERRMSG_MAXLEN];
  1219. static const char unknown[14] = {
  1220. 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
  1221. };
  1222. retval = EINVAL;
  1223. #if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
  1224. /* Need to translate errno to string index. */
  1225. for (i = 0 ; i < sizeof(estridx)/sizeof(estridx[0]) ; i++) {
  1226. if (estridx[i] == errnum) {
  1227. goto GOT_ESTRIDX;
  1228. }
  1229. }
  1230. i = INT_MAX; /* Failed, but may need to check mips special case. */
  1231. #ifdef __mips__
  1232. if (errnum == EDQUOT) { /* Deal with large EDQUOT value on mips */
  1233. i = 122;
  1234. }
  1235. #endif /* __mips__ */
  1236. GOT_ESTRIDX:
  1237. #else
  1238. /* No errno to string index translation needed. */
  1239. i = errnum;
  1240. #endif
  1241. if (((unsigned int) i) < _SYS_NERR) {
  1242. /* Trade time for space. This function should rarely be called
  1243. * so rather than keeping an array of pointers for the different
  1244. * messages, just run through the buffer until we find the
  1245. * correct string. */
  1246. for (s = (char *) _string_syserrmsgs ; i ; ++s) {
  1247. if (!*s) {
  1248. --i;
  1249. }
  1250. }
  1251. if (*s) { /* Make sure we have an actual message. */
  1252. retval = 0;
  1253. goto GOT_MESG;
  1254. }
  1255. }
  1256. s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
  1257. memcpy(s, unknown, sizeof(unknown));
  1258. GOT_MESG:
  1259. if (!strerrbuf) { /* SUSv3 */
  1260. buflen = 0;
  1261. }
  1262. i = strlen(s) + 1;
  1263. if (i > buflen) {
  1264. i = buflen;
  1265. retval = ERANGE;
  1266. }
  1267. if (i) {
  1268. memcpy(strerrbuf, s, i);
  1269. strerrbuf[i-1] = 0; /* In case buf was too small. */
  1270. }
  1271. if (retval) {
  1272. __set_errno(retval);
  1273. }
  1274. return retval;
  1275. }
  1276. #endif
  1277. /**********************************************************************/
  1278. /* GNU extension functions. */
  1279. /**********************************************************************/
  1280. #ifdef L__glibc_strerror_r
  1281. weak_alias(_glibc_strerror_r,__strerror_r);
  1282. char *_glibc_strerror_r(int errnum, char *strerrbuf, size_t buflen)
  1283. {
  1284. _susv3_strerror_r(errnum, strerrbuf, buflen);
  1285. return strerrbuf;
  1286. }
  1287. #endif
  1288. /**********************************************************************/
  1289. #ifdef L_wmempcpy
  1290. #define L_mempcpy
  1291. #define Wmempcpy wmempcpy
  1292. #else
  1293. #define Wmempcpy mempcpy
  1294. #endif
  1295. #ifdef L_mempcpy
  1296. #ifndef L_wmempcpy
  1297. /* uClibc's old string implementation did this to cater to some app. */
  1298. weak_alias(mempcpy,__mempcpy);
  1299. #endif
  1300. Wvoid *Wmempcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
  1301. {
  1302. register Wchar *r1 = s1;
  1303. register const Wchar *r2 = s2;
  1304. #ifdef __BCC__
  1305. while (n--) {
  1306. *r1++ = *r2++;
  1307. }
  1308. #else
  1309. while (n) {
  1310. *r1++ = *r2++;
  1311. --n;
  1312. }
  1313. #endif
  1314. return r1;
  1315. }
  1316. #endif
  1317. /**********************************************************************/
  1318. #ifdef L_memrchr
  1319. void *memrchr(const void *s, int c, size_t n)
  1320. {
  1321. register const unsigned char *r;
  1322. #ifdef __BCC__
  1323. /* bcc can optimize the counter if it thinks it is a pointer... */
  1324. register const char *np = (const char *) n;
  1325. #else
  1326. #define np n
  1327. #endif
  1328. r = ((unsigned char *)s) + ((size_t) np);
  1329. while (np) {
  1330. if (*--r == ((unsigned char)c)) {
  1331. return (void *) r; /* silence the warning */
  1332. }
  1333. --np;
  1334. }
  1335. return NULL;
  1336. }
  1337. #undef np
  1338. #endif
  1339. /**********************************************************************/
  1340. #ifdef L_wcpcpy
  1341. #define L_stpcpy
  1342. #define Wstpcpy wcpcpy
  1343. #else
  1344. #define Wstpcpy stpcpy
  1345. #endif
  1346. #ifdef L_stpcpy
  1347. Wchar *Wstpcpy(register Wchar * __restrict s1, const Wchar * __restrict s2)
  1348. {
  1349. #ifdef __BCC__
  1350. do {
  1351. *s1 = *s2++;
  1352. } while (*s1++ != 0);
  1353. #else
  1354. while ( (*s1++ = *s2++) != 0 );
  1355. #endif
  1356. return s1 - 1;
  1357. }
  1358. #endif
  1359. /**********************************************************************/
  1360. #ifdef L_wcpncpy
  1361. #define L_stpncpy
  1362. #define Wstpncpy wcpncpy
  1363. #else
  1364. #define Wstpncpy stpncpy
  1365. #endif
  1366. #ifdef L_stpncpy
  1367. Wchar *Wstpncpy(register Wchar * __restrict s1,
  1368. register const Wchar * __restrict s2,
  1369. size_t n)
  1370. {
  1371. Wchar *s = s1;
  1372. const Wchar *p = s2;
  1373. #ifdef __BCC__
  1374. while (n--) {
  1375. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  1376. ++s;
  1377. }
  1378. return s1 + (s2 - p);
  1379. #else
  1380. while (n) {
  1381. if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
  1382. ++s;
  1383. --n;
  1384. }
  1385. return s1 + (s2 - p);
  1386. #endif
  1387. }
  1388. #endif
  1389. /**********************************************************************/
  1390. #ifdef L_bzero
  1391. void bzero(void *s, size_t n)
  1392. {
  1393. register unsigned char *p = s;
  1394. #ifdef __BCC__
  1395. /* bcc can optimize the counter if it thinks it is a pointer... */
  1396. register const char *np = (const char *) n;
  1397. #else
  1398. #define np n
  1399. #endif
  1400. while (np) {
  1401. *p++ = 0;
  1402. --np;
  1403. }
  1404. }
  1405. #undef np
  1406. #endif
  1407. /**********************************************************************/
  1408. #ifdef L_bcopy
  1409. void bcopy(const void *s2, void *s1, size_t n)
  1410. {
  1411. #if 1
  1412. memmove(s1, s2, n);
  1413. #else
  1414. #ifdef __BCC__
  1415. register char *s;
  1416. register const char *p;
  1417. s = s1;
  1418. p = s2;
  1419. if (p >= s) {
  1420. while (n--) {
  1421. *s++ = *p++;
  1422. }
  1423. } else {
  1424. s += n;
  1425. p += n;
  1426. while (n--) {
  1427. *--s = *--p;
  1428. }
  1429. }
  1430. #else
  1431. register char *s;
  1432. register const char *p;
  1433. s = s1;
  1434. p = s2;
  1435. if (p >= s) {
  1436. while (n) {
  1437. *s++ = *p++;
  1438. --n;
  1439. }
  1440. } else {
  1441. while (n) {
  1442. --n;
  1443. s[n] = p[n];
  1444. }
  1445. }
  1446. #endif
  1447. #endif
  1448. }
  1449. #endif
  1450. /**********************************************************************/
  1451. #ifdef L_strcasestr
  1452. char *strcasestr(const char *s1, const char *s2)
  1453. {
  1454. register const char *s = s1;
  1455. register const char *p = s2;
  1456. #if 1
  1457. do {
  1458. if (!*p) {
  1459. return (char *) s1;;
  1460. }
  1461. if ((*p == *s)
  1462. || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
  1463. ) {
  1464. ++p;
  1465. ++s;
  1466. } else {
  1467. p = s2;
  1468. if (!*s) {
  1469. return NULL;
  1470. }
  1471. s = ++s1;
  1472. }
  1473. } while (1);
  1474. #else
  1475. while (*p && *s) {
  1476. if ((*p == *s)
  1477. || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
  1478. ) {
  1479. ++p;
  1480. ++s;
  1481. } else {
  1482. p = s2;
  1483. s = ++s1;
  1484. }
  1485. }
  1486. return (*p) ? NULL : (char *) s1;
  1487. #endif
  1488. }
  1489. #endif
  1490. /**********************************************************************/
  1491. #ifdef L_strndup
  1492. char *strndup(register const char *s1, size_t n)
  1493. {
  1494. register char *s;
  1495. n = strnlen(s1,n); /* Avoid problems if s1 not nul-terminated. */
  1496. if ((s = malloc(n + 1)) != NULL) {
  1497. memcpy(s, s1, n);
  1498. s[n] = 0;
  1499. }
  1500. return s;
  1501. }
  1502. #endif
  1503. /**********************************************************************/
  1504. #ifdef L_strsep
  1505. char *strsep(char ** __restrict s1, const char * __restrict s2)
  1506. {
  1507. register char *s = *s1;
  1508. register char *p;
  1509. #if 1
  1510. p = NULL;
  1511. if (s && *s && (p = strpbrk(s, s2))) {
  1512. *p++ = 0;
  1513. }
  1514. #else
  1515. if (s && *s && *(p = s + strcspn(s, s2))) {
  1516. *p++ = 0;
  1517. } else {
  1518. p = NULL;
  1519. }
  1520. #endif
  1521. *s1 = p;
  1522. return s;
  1523. }
  1524. #endif
  1525. /**********************************************************************/
  1526. #ifdef L_wcschrnul
  1527. #define L_strchrnul
  1528. #define __Wstrchrnul __wcschrnul
  1529. #define Wstrchrnul wcschrnul
  1530. #else
  1531. #define __Wstrchrnul __strchrnul
  1532. #define Wstrchrnul strchrnul
  1533. #endif
  1534. #ifdef L_strchrnul
  1535. extern Wchar *__Wstrchrnul(register const Wchar *s, Wint c);
  1536. weak_alias(__Wstrchrnul, Wstrchrnul);
  1537. Wchar *__Wstrchrnul(register const Wchar *s, Wint c)
  1538. {
  1539. --s;
  1540. while (*++s && (*s != ((Wchar)c)));
  1541. return (Wchar *) s;
  1542. }
  1543. #endif
  1544. /**********************************************************************/
  1545. #ifdef L_rawmemchr
  1546. void *rawmemchr(const void *s, int c)
  1547. {
  1548. register const unsigned char *r = s;
  1549. while (*r != ((unsigned char)c)) ++r;
  1550. return (void *) r; /* silence the warning */
  1551. }
  1552. #endif
  1553. /**********************************************************************/
  1554. #ifdef L_basename
  1555. char *basename(const char *path)
  1556. {
  1557. register const char *s;
  1558. register const char *p;
  1559. p = s = path;
  1560. while (*s) {
  1561. if (*s++ == '/') {
  1562. p = s;
  1563. }
  1564. }
  1565. return (char *) p;
  1566. }
  1567. #endif
  1568. /**********************************************************************/
  1569. #ifdef L___xpg_basename
  1570. char *__xpg_basename(register char *path)
  1571. {
  1572. static const char null_or_empty[] = ".";
  1573. char *first;
  1574. register char *last;
  1575. first = (char *) null_or_empty;
  1576. if (path && *path) {
  1577. first = path;
  1578. last = path - 1;
  1579. do {
  1580. if ((*path != '/') && (path > ++last)) {
  1581. last = first = path;
  1582. }
  1583. } while (*++path);
  1584. if (*first == '/') {
  1585. last = first;
  1586. }
  1587. last[1] = 0;
  1588. }
  1589. return first;
  1590. }
  1591. #endif
  1592. /**********************************************************************/
  1593. #ifdef L_dirname
  1594. char *dirname(char *path)
  1595. {
  1596. static const char null_or_empty_or_noslash[] = ".";
  1597. register char *s;
  1598. register char *last;
  1599. char *first;
  1600. last = s = path;
  1601. if (s != NULL) {
  1602. LOOP:
  1603. while (*s && (*s != '/')) ++s;
  1604. first = s;
  1605. while (*s == '/') ++s;
  1606. if (*s) {
  1607. last = first;
  1608. goto LOOP;
  1609. }
  1610. if (last == path) {
  1611. if (*last != '/') {
  1612. goto DOT;
  1613. }
  1614. if ((*++last == '/') && (last[1] == 0)) {
  1615. ++last;
  1616. }
  1617. }
  1618. *last = 0;
  1619. return path;
  1620. }
  1621. DOT:
  1622. return (char *) null_or_empty_or_noslash;
  1623. }
  1624. #endif
  1625. /**********************************************************************/
  1626. #ifdef L_strlcat
  1627. /* OpenBSD function:
  1628. * Append at most n-1-strlen(dst) chars from src to dst and nul-terminate dst.
  1629. * Returns strlen(src) + strlen({original} dst), so truncation occurred if the
  1630. * return val is >= n.
  1631. * Note: If dst doesn't contain a nul in the first n chars, strlen(dst) is
  1632. * taken as n. */
  1633. size_t strlcat(register char *__restrict dst,
  1634. register const char *__restrict src,
  1635. size_t n)
  1636. {
  1637. size_t len;
  1638. char dummy[1];
  1639. len = 0;
  1640. while (1) {
  1641. if (len >= n) {
  1642. dst = dummy;
  1643. break;
  1644. }
  1645. if (!*dst) {
  1646. break;
  1647. }
  1648. ++dst;
  1649. ++len;
  1650. }
  1651. while ((*dst = *src) != 0) {
  1652. if (++len < n) {
  1653. ++dst;
  1654. }
  1655. ++src;
  1656. }
  1657. return len;
  1658. }
  1659. #endif
  1660. /**********************************************************************/
  1661. #ifdef L_strlcpy
  1662. /* OpenBSD function:
  1663. * Copy at most n-1 chars from src to dst and nul-terminate dst.
  1664. * Returns strlen(src), so truncation occurred if the return value is >= n. */
  1665. size_t strlcpy(register char *__restrict dst,
  1666. register const char *__restrict src,
  1667. size_t n)
  1668. {
  1669. const char *src0 = src;
  1670. char dummy[1];
  1671. if (!n) {
  1672. dst = dummy;
  1673. } else {
  1674. --n;
  1675. }
  1676. while ((*dst = *src) != 0) {
  1677. if (n) {
  1678. --n;
  1679. ++dst;
  1680. }
  1681. ++src;
  1682. }
  1683. return src - src0;
  1684. }
  1685. #endif
  1686. /**********************************************************************/
  1687. #ifdef L__string_syssigmsgs
  1688. const char _string_syssigmsgs[] = {
  1689. /* 0: 0, 1 */ "\0"
  1690. /* 1: 1, 7 */ "Hangup\0"
  1691. /* 2: 8, 10 */ "Interrupt\0"
  1692. /* 3: 18, 5 */ "Quit\0"
  1693. /* 4: 23, 20 */ "Illegal instruction\0"
  1694. /* 5: 43, 22 */ "Trace/breakpoint trap\0"
  1695. /* 6: 65, 8 */ "Aborted\0"
  1696. /* 7: 73, 10 */ "Bus error\0"
  1697. /* 8: 83, 25 */ "Floating point exception\0"
  1698. /* 9: 108, 7 */ "Killed\0"
  1699. /* 10: 115, 22 */ "User defined signal 1\0"
  1700. /* 11: 137, 19 */ "Segmentation fault\0"
  1701. /* 12: 156, 22 */ "User defined signal 2\0"
  1702. /* 13: 178, 12 */ "Broken pipe\0"
  1703. /* 14: 190, 12 */ "Alarm clock\0"
  1704. /* 15: 202, 11 */ "Terminated\0"
  1705. /* 16: 213, 12 */ "Stack fault\0"
  1706. /* 17: 225, 13 */ "Child exited\0"
  1707. /* 18: 238, 10 */ "Continued\0"
  1708. /* 19: 248, 17 */ "Stopped (signal)\0"
  1709. /* 20: 265, 8 */ "Stopped\0"
  1710. /* 21: 273, 20 */ "Stopped (tty input)\0"
  1711. /* 22: 293, 21 */ "Stopped (tty output)\0"
  1712. /* 23: 314, 21 */ "Urgent I/O condition\0"
  1713. /* 24: 335, 24 */ "CPU time limit exceeded\0"
  1714. /* 25: 359, 25 */ "File size limit exceeded\0"
  1715. /* 26: 384, 22 */ "Virtual timer expired\0"
  1716. /* 27: 406, 24 */ "Profiling timer expired\0"
  1717. /* 28: 430, 15 */ "Window changed\0"
  1718. /* 29: 445, 13 */ "I/O possible\0"
  1719. /* 30: 458, 14 */ "Power failure\0"
  1720. /* 31: 472, 16 */ "Bad system call"
  1721. };
  1722. #endif
  1723. /**********************************************************************/
  1724. #ifdef L_sys_siglist
  1725. const char *const sys_siglist[_NSIG] = {
  1726. NULL,
  1727. _string_syssigmsgs + 1,
  1728. _string_syssigmsgs + 8,
  1729. _string_syssigmsgs + 18,
  1730. _string_syssigmsgs + 23,
  1731. _string_syssigmsgs + 43,
  1732. _string_syssigmsgs + 65,
  1733. _string_syssigmsgs + 73,
  1734. _string_syssigmsgs + 83,
  1735. _string_syssigmsgs + 108,
  1736. _string_syssigmsgs + 115,
  1737. _string_syssigmsgs + 137,
  1738. _string_syssigmsgs + 156,
  1739. _string_syssigmsgs + 178,
  1740. _string_syssigmsgs + 190,
  1741. _string_syssigmsgs + 202,
  1742. _string_syssigmsgs + 213,
  1743. _string_syssigmsgs + 225,
  1744. _string_syssigmsgs + 238,
  1745. _string_syssigmsgs + 248,
  1746. _string_syssigmsgs + 265,
  1747. _string_syssigmsgs + 273,
  1748. _string_syssigmsgs + 293,
  1749. _string_syssigmsgs + 314,
  1750. _string_syssigmsgs + 335,
  1751. _string_syssigmsgs + 359,
  1752. _string_syssigmsgs + 384,
  1753. _string_syssigmsgs + 406,
  1754. _string_syssigmsgs + 430,
  1755. _string_syssigmsgs + 445,
  1756. _string_syssigmsgs + 458,
  1757. _string_syssigmsgs + 472,
  1758. NULL,
  1759. NULL,
  1760. NULL,
  1761. NULL,
  1762. NULL,
  1763. NULL,
  1764. NULL,
  1765. NULL,
  1766. NULL,
  1767. NULL,
  1768. NULL,
  1769. NULL,
  1770. NULL,
  1771. NULL,
  1772. NULL,
  1773. NULL,
  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. };
  1791. #endif
  1792. /**********************************************************************/
  1793. #ifdef L_strsignal
  1794. /* TODO: make a threadsafe version? */
  1795. char *strsignal(int signum)
  1796. {
  1797. register char *s;
  1798. int i;
  1799. static char buf[_STRSIGNAL_BUFSIZE];
  1800. static const char unknown[15] = {
  1801. 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' '
  1802. };
  1803. if (((unsigned int) signum) < _SYS_NSIG) {
  1804. /* Trade time for space. This function should rarely be called
  1805. * so rather than keeping an array of pointers for the different
  1806. * messages, just run through the buffer until we find the
  1807. * correct string. */
  1808. for (s = (char *) _string_syssigmsgs, i = signum ; i ; ++s) {
  1809. if (!*s) {
  1810. --i;
  1811. }
  1812. }
  1813. if (*s) { /* Make sure we have an actual message. */
  1814. goto DONE;
  1815. }
  1816. }
  1817. s = _int10tostr(buf+sizeof(buf)-1, signum) - sizeof(unknown);
  1818. memcpy(s, unknown, sizeof(unknown));
  1819. DONE:
  1820. return s;
  1821. }
  1822. #endif
  1823. /**********************************************************************/
  1824. #ifdef L_psignal
  1825. /* TODO: make this threadsafe with a reentrant version of strsignal? */
  1826. void psignal(int signum, register const char *message)
  1827. {
  1828. /* If the program is calling psignal, it's a safe bet that printf and
  1829. * friends are used as well. It is also possible that the calling
  1830. * program could buffer stderr, or reassign it. */
  1831. register const char *sep;
  1832. sep = ": ";
  1833. if (!(message && *message)) { /* Caller did not supply a prefix message */
  1834. message = (sep += 2); /* or passed an empty string. */
  1835. }
  1836. #if 1
  1837. fprintf(stderr, "%s%s%s\n", message, sep, strsignal(signum));
  1838. #else
  1839. /* Note: Assumes stderr not closed or buffered. */
  1840. __STDIO_THREADLOCK(stderr);
  1841. _stdio_fdout(STDERR_FILENO, message, sep, strsignal(signum));
  1842. __STDIO_THREADUNLOCK(stderr);
  1843. #endif
  1844. }
  1845. #endif
  1846. /**********************************************************************/