wstring.c 45 KB

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