Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

397 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. s_perror.c
  5. Abstract:
  6. This module implements the s_perror() operation used by the
  7. tcp/ip utilities. This is a temporary workaround for beta.
  8. This will be replaced by NLS support for the final product.
  9. Author:
  10. John Ballard (jballard) June 15, 1992
  11. Revision History:
  12. Ronald Meijer (ronaldm) NLS Enabled Nov 26, 1992
  13. --*/
  14. #include <stdio.h>
  15. #include <crt\errno.h>
  16. #include <sock_err.h>
  17. #include <winsock.h>
  18. #include "nlstxt.h"
  19. #define MAX_MSGTABLE 255
  20. extern HMODULE hWinStrm;
  21. extern int WSA_perror(
  22. char *yourmsg,
  23. int lerrno);
  24. void
  25. s_perror(
  26. char *yourmsg,
  27. int lerrno)
  28. {
  29. WCHAR perrW[MAX_MSGTABLE+1];
  30. CHAR perr[MAX_MSGTABLE+1];
  31. unsigned msglen;
  32. unsigned usMsgNum;
  33. switch (lerrno) {
  34. // case EZERO:
  35. // perr = "Error 0";
  36. // break;
  37. case EPERM:
  38. usMsgNum = IDS_EPERM ;
  39. break;
  40. case ENOENT:
  41. usMsgNum = IDS_ENOENT ;
  42. break;
  43. case ESRCH:
  44. usMsgNum = IDS_ESRCH ;
  45. break;
  46. case EINTR:
  47. usMsgNum = IDS_EINTR ;
  48. break;
  49. case EIO:
  50. usMsgNum = IDS_EIO ;
  51. break;
  52. case ENXIO:
  53. usMsgNum = IDS_ENXIO ;
  54. break;
  55. case E2BIG:
  56. usMsgNum = IDS_E2BIG ;
  57. break;
  58. case ENOEXEC:
  59. usMsgNum = IDS_ENOEXEC ;
  60. break;
  61. case EBADF:
  62. usMsgNum = IDS_EBADF ;
  63. break;
  64. case ECHILD:
  65. usMsgNum = IDS_ECHILD ;
  66. break;
  67. case EAGAIN:
  68. usMsgNum = IDS_EAGAIN ;
  69. break;
  70. case ENOMEM:
  71. usMsgNum = IDS_ENOMEM ;
  72. break;
  73. case EACCES:
  74. usMsgNum = IDS_EACCES ;
  75. break;
  76. case EFAULT:
  77. usMsgNum = IDS_EFAULT ;
  78. break;
  79. // case ENOTBLK:
  80. // perr = "Block device required";
  81. // break;
  82. case EBUSY:
  83. usMsgNum = IDS_EBUSY ;
  84. break;
  85. case EEXIST:
  86. usMsgNum = IDS_EEXIST ;
  87. break;
  88. case EXDEV:
  89. usMsgNum = IDS_EXDEV ;
  90. break;
  91. case ENODEV:
  92. usMsgNum = IDS_ENODEV ;
  93. break;
  94. case ENOTDIR:
  95. usMsgNum = IDS_ENOTDIR ;
  96. break;
  97. case EISDIR:
  98. usMsgNum = IDS_EISDIR ;
  99. break;
  100. case EINVAL:
  101. usMsgNum = IDS_EINVAL ;
  102. break;
  103. case ENFILE:
  104. usMsgNum = IDS_ENFILE ;
  105. break;
  106. case EMFILE:
  107. usMsgNum = IDS_EMFILE ;
  108. break;
  109. case ENOTTY:
  110. usMsgNum = IDS_EMFILE ;
  111. break;
  112. // case ETXTBSY:
  113. // perr = "Text file busy";
  114. // break;
  115. case EFBIG:
  116. usMsgNum = IDS_EFBIG ;
  117. break;
  118. case ENOSPC:
  119. usMsgNum = IDS_ENOSPC ;
  120. break;
  121. case ESPIPE:
  122. usMsgNum = IDS_ESPIPE ;
  123. break;
  124. case EROFS:
  125. usMsgNum = IDS_EROFS ;
  126. break;
  127. case EMLINK:
  128. usMsgNum = IDS_EMLINK ;
  129. break;
  130. case EPIPE:
  131. usMsgNum = IDS_EPIPE ;
  132. break;
  133. case EDOM:
  134. usMsgNum = IDS_EDOM ;
  135. break;
  136. case ERANGE:
  137. usMsgNum = IDS_ERANGE ;
  138. break;
  139. // case EUCLEAN:
  140. // perr = "File system not clean";
  141. // break;
  142. case EDEADLK:
  143. usMsgNum = IDS_EDEADLK ;
  144. break;
  145. case ENOMSG:
  146. usMsgNum = IDS_ENOMSG ;
  147. break;
  148. case EIDRM:
  149. usMsgNum = IDS_EIDRM ;
  150. break;
  151. case ECHRNG:
  152. usMsgNum = IDS_ECHRNG ;
  153. break;
  154. case EL2NSYNC:
  155. usMsgNum = IDS_EL2NSYNC ;
  156. break;
  157. case EL3HLT:
  158. usMsgNum = IDS_EL3HLT ;
  159. break;
  160. case EL3RST:
  161. usMsgNum = IDS_EL3RST ;
  162. break;
  163. case ELNRNG:
  164. usMsgNum = IDS_ELNRNG ;
  165. break;
  166. case EUNATCH:
  167. usMsgNum = IDS_EUNATCH ;
  168. break;
  169. case ENOCSI:
  170. usMsgNum = IDS_ENOCSI ;
  171. break;
  172. case EL2HLT:
  173. usMsgNum = IDS_EL2HLT ;
  174. break;
  175. case EBADE:
  176. usMsgNum = IDS_EBADE ;
  177. break;
  178. case EBADR:
  179. usMsgNum = IDS_EBADR ;
  180. break;
  181. case EXFULL:
  182. usMsgNum = IDS_EXFULL ;
  183. break;
  184. case ENOANO:
  185. usMsgNum = IDS_ENOANO ;
  186. break;
  187. case EBADRQC:
  188. usMsgNum = IDS_EBADRQC ;
  189. break;
  190. case EBADSLT:
  191. usMsgNum = IDS_EBADSLT ;
  192. break;
  193. case EBFONT:
  194. usMsgNum = IDS_EBFONT ;
  195. break;
  196. case ENOSTR:
  197. usMsgNum = IDS_ENOSTR ;
  198. break;
  199. case ENODATA:
  200. usMsgNum = IDS_ENODATA ;
  201. break;
  202. case ETIME:
  203. usMsgNum = IDS_ETIME ;
  204. break;
  205. case ENOSR:
  206. usMsgNum = IDS_ENOSR ;
  207. break;
  208. case ENONET:
  209. usMsgNum = IDS_ENONET ;
  210. break;
  211. case ENOPKG:
  212. usMsgNum = IDS_ENOPKG ;
  213. break;
  214. case EREMOTE:
  215. usMsgNum = IDS_EREMOTE ;
  216. break;
  217. case ENOLINK:
  218. usMsgNum = IDS_ENOLINK ;
  219. break;
  220. case EADV:
  221. usMsgNum = IDS_EADV ;
  222. break;
  223. case ESRMNT:
  224. usMsgNum = IDS_ESRMNT ;
  225. break;
  226. case ECOMM:
  227. usMsgNum = IDS_ECOMM ;
  228. break;
  229. case EPROTO:
  230. usMsgNum = IDS_EPROTO ;
  231. break;
  232. case EMULTIHOP:
  233. usMsgNum = IDS_EMULTIHOP ;
  234. break;
  235. case ELBIN:
  236. usMsgNum = IDS_ELBIN ;
  237. break;
  238. case EDOTDOT:
  239. usMsgNum = IDS_EDOTDOT ;
  240. break;
  241. case EBADMSG:
  242. usMsgNum = IDS_EBADMSG ;
  243. break;
  244. case ENOTUNIQ:
  245. usMsgNum = IDS_ENOTUNIQ ;
  246. break;
  247. case EREMCHG:
  248. usMsgNum = IDS_EREMCHG ;
  249. break;
  250. case ELIBACC:
  251. usMsgNum = IDS_ELIBACC;
  252. break;
  253. case ELIBBAD:
  254. usMsgNum = IDS_ELIBBAD ;
  255. break;
  256. case ELIBSCN:
  257. usMsgNum = IDS_ELIBSCN ;
  258. break;
  259. case ELIBMAX:
  260. usMsgNum = IDS_ELIBMAX ;
  261. break;
  262. case ELIBEXEC:
  263. usMsgNum = IDS_ELIBEXEC ;
  264. break;
  265. case ENOTSOCK:
  266. usMsgNum = IDS_ENOTSOCK ;
  267. break;
  268. case EADDRNOTAVAIL:
  269. usMsgNum = IDS_EADDRNOTAVAIL ;
  270. break;
  271. case EADDRINUSE:
  272. usMsgNum = IDS_EADDRINUSE ;
  273. break;
  274. case EAFNOSUPPORT:
  275. usMsgNum = IDS_EAFNOSUPPORT ;
  276. break;
  277. case ESOCKTNOSUPPORT:
  278. usMsgNum = IDS_ESOCKTNOSUPPORT ;
  279. break;
  280. case EPROTONOSUPPORT:
  281. usMsgNum = IDS_EPROTONOSUPPORT ;
  282. break;
  283. case ENOBUFS:
  284. usMsgNum = IDS_ENOBUFS ;
  285. break;
  286. case ETIMEDOUT:
  287. usMsgNum = IDS_ETIMEDOUT ;
  288. break;
  289. case EISCONN:
  290. usMsgNum = IDS_EISCONN ;
  291. break;
  292. case ENOTCONN:
  293. usMsgNum = IDS_ENOTCONN ;
  294. break;
  295. case ENOPROTOOPT:
  296. usMsgNum = IDS_ENOPROTOOPT ;
  297. break;
  298. case ECONNRESET:
  299. usMsgNum = IDS_ECONNRESET ;
  300. break;
  301. case ECONNABORT:
  302. usMsgNum = IDS_ECONNABORT ;
  303. break;
  304. case ENETDOWN:
  305. usMsgNum = IDS_ENETDOWN ;
  306. break;
  307. case ECONNREFUSED:
  308. usMsgNum = IDS_ECONNREFUSED ;
  309. break;
  310. case EHOSTUNREACH:
  311. usMsgNum = IDS_EHOSTUNREACH ;
  312. break;
  313. case EPROTOTYPE:
  314. usMsgNum = IDS_EPROTOTYPE ;
  315. break;
  316. case EOPNOTSUPP:
  317. usMsgNum = IDS_EOPNOTSUPP ;
  318. break;
  319. case ESUBNET:
  320. usMsgNum = IDS_ESUBNET ;
  321. break;
  322. case ENETNOLNK:
  323. usMsgNum = IDS_ENETNOLNK ;
  324. break;
  325. case EBADIOCTL:
  326. usMsgNum = IDS_EBADIOCTL ;
  327. break;
  328. case ERESOURCE:
  329. usMsgNum = IDS_ERESOURCE ;
  330. break;
  331. case EPROTUNR:
  332. usMsgNum = IDS_EPROTUNR ;
  333. break;
  334. case EPORTUNR:
  335. usMsgNum = IDS_EPORTUNR ;
  336. break;
  337. case ENETUNR:
  338. usMsgNum = IDS_ENETUNR ;
  339. break;
  340. case EPACKET:
  341. usMsgNum = IDS_EPACKET ;
  342. break;
  343. case ETYPEREG:
  344. usMsgNum = IDS_ETYPEREG ;
  345. break;
  346. case ENOTINIT:
  347. usMsgNum = IDS_ENOTINIT ;
  348. break;
  349. default:
  350. if (WSA_perror(yourmsg, lerrno)) {
  351. return;
  352. }
  353. usMsgNum = IDS_UNKNOWN ;
  354. break;
  355. }
  356. if (hWinStrm == NULL)
  357. hWinStrm = GetModuleHandle( "winstrm" );
  358. if (!(msglen = FormatMessageW(
  359. FORMAT_MESSAGE_FROM_HMODULE,
  360. (LPVOID)hWinStrm,
  361. usMsgNum,
  362. 0L,
  363. perrW,
  364. MAX_MSGTABLE,
  365. NULL)))
  366. return;
  367. WideCharToMultiByte(CP_OEMCP,
  368. 0,
  369. perrW,
  370. -1,
  371. perr,
  372. sizeof(perr),
  373. NULL,
  374. NULL);
  375. fprintf(stderr, "> %s:%s\n", yourmsg, perr);
  376. return;
  377. }