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.

218 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. w_perror.c
  5. Abstract:
  6. This module implements the WSA_perror() operation used by the
  7. p_error function. 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 <winsock.h>
  16. #include "nlstxt.h"
  17. #define MAX_MSGTABLE 255
  18. HMODULE hWinStrm = NULL;
  19. int WSA_perror(
  20. char *yourmsg,
  21. int lerrno)
  22. {
  23. WCHAR perrW[MAX_MSGTABLE+1];
  24. CHAR perr[MAX_MSGTABLE+1];
  25. unsigned msglen;
  26. unsigned usMsgNum;
  27. switch (lerrno) {
  28. case WSAENAMETOOLONG:
  29. usMsgNum = IDS_WSAENAMETOOLONG;
  30. break;
  31. case WSASYSNOTREADY:
  32. usMsgNum = IDS_WSASYSNOTREADY;
  33. break;
  34. case WSAVERNOTSUPPORTED:
  35. usMsgNum = IDS_WSAVERNOTSUPPORTED;
  36. break;
  37. case WSAESHUTDOWN:
  38. usMsgNum = IDS_WSAESHUTDOWN;
  39. break;
  40. case WSAEINTR:
  41. usMsgNum = IDS_WSAEINTR;
  42. break;
  43. case WSAHOST_NOT_FOUND:
  44. usMsgNum = IDS_WSAHOST_NOT_FOUND;
  45. break;
  46. case WSATRY_AGAIN:
  47. usMsgNum = IDS_WSATRY_AGAIN;
  48. break;
  49. case WSANO_RECOVERY:
  50. usMsgNum = IDS_WSANO_RECOVERY;
  51. break;
  52. case WSANO_DATA:
  53. usMsgNum = IDS_WSANO_DATA;
  54. break;
  55. case WSAEBADF:
  56. usMsgNum = IDS_WSAEBADF;
  57. break;
  58. case WSAEWOULDBLOCK:
  59. usMsgNum = IDS_WSAEWOULDBLOCK;
  60. break;
  61. case WSAEINPROGRESS:
  62. usMsgNum = IDS_WSAEINPROGRESS;
  63. break;
  64. case WSAEALREADY:
  65. usMsgNum = IDS_WSAEALREADY;
  66. break;
  67. case WSAEFAULT:
  68. usMsgNum = IDS_WSAEFAULT;
  69. break;
  70. case WSAEDESTADDRREQ:
  71. usMsgNum = IDS_WSAEDESTADDRREQ;
  72. break;
  73. case WSAEMSGSIZE:
  74. usMsgNum = IDS_WSAEMSGSIZE;
  75. break;
  76. case WSAEPFNOSUPPORT:
  77. usMsgNum = IDS_WSAEPFNOSUPPORT;
  78. break;
  79. case WSAENOTEMPTY:
  80. usMsgNum = IDS_WSAENOTEMPTY;
  81. break;
  82. case WSAEPROCLIM:
  83. usMsgNum = IDS_WSAEPROCLIM;
  84. break;
  85. case WSAEUSERS:
  86. usMsgNum = IDS_WSAEUSERS;
  87. break;
  88. case WSAEDQUOT:
  89. usMsgNum = IDS_WSAEDQUOT;
  90. break;
  91. case WSAESTALE:
  92. usMsgNum = IDS_WSAESTALE;
  93. break;
  94. case WSAEINVAL:
  95. usMsgNum = IDS_WSAEINVAL;
  96. break;
  97. case WSAEMFILE:
  98. usMsgNum = IDS_WSAEMFILE;
  99. break;
  100. case WSAELOOP:
  101. usMsgNum = IDS_WSAELOOP;
  102. break;
  103. case WSAEREMOTE:
  104. usMsgNum = IDS_WSAEREMOTE;
  105. break;
  106. case WSAENOTSOCK:
  107. usMsgNum = IDS_WSAENOTSOCK;
  108. break;
  109. case WSAEADDRNOTAVAIL:
  110. usMsgNum = IDS_WSAEADDRNOTAVAIL;
  111. break;
  112. case WSAEADDRINUSE:
  113. usMsgNum = IDS_WSAEADDRINUSE;
  114. break;
  115. case WSAEAFNOSUPPORT:
  116. usMsgNum = IDS_WSAEAFNOSUPPORT;
  117. break;
  118. case WSAESOCKTNOSUPPORT:
  119. usMsgNum = IDS_WSAESOCKTNOSUPPORT;
  120. break;
  121. case WSAEPROTONOSUPPORT:
  122. usMsgNum = IDS_WSAEPROTONOSUPPORT;
  123. break;
  124. case WSAENOBUFS:
  125. usMsgNum = IDS_WSAENOBUFS;
  126. break;
  127. case WSAETIMEDOUT:
  128. usMsgNum = IDS_WSAETIMEDOUT;
  129. break;
  130. case WSAEISCONN:
  131. usMsgNum = IDS_WSAEISCONN;
  132. break;
  133. case WSAENOTCONN:
  134. usMsgNum = IDS_WSAENOTCONN;
  135. break;
  136. case WSAENOPROTOOPT:
  137. usMsgNum = IDS_WSAENOPROTOOPT;
  138. break;
  139. case WSAECONNRESET:
  140. usMsgNum = IDS_WSAECONNRESET;
  141. break;
  142. case WSAECONNABORTED:
  143. usMsgNum = IDS_WSAECONNABORTED;
  144. break;
  145. case WSAENETDOWN:
  146. usMsgNum = IDS_WSAENETDOWN;
  147. break;
  148. case WSAENETRESET:
  149. usMsgNum = IDS_WSAENETRESET;
  150. break;
  151. case WSAECONNREFUSED:
  152. usMsgNum = IDS_WSAECONNREFUSED;
  153. break;
  154. case WSAEHOSTDOWN:
  155. usMsgNum = IDS_WSAEHOSTDOWN;
  156. break;
  157. case WSAEHOSTUNREACH:
  158. usMsgNum = IDS_WSAEHOSTUNREACH;
  159. break;
  160. case WSAEPROTOTYPE:
  161. usMsgNum = IDS_WSAEPROTOTYPE;
  162. break;
  163. case WSAEOPNOTSUPP:
  164. usMsgNum = IDS_WSAEOPNOTSUPP;
  165. break;
  166. case WSAENETUNREACH:
  167. usMsgNum = IDS_WSAENETUNREACH;
  168. break;
  169. case WSAETOOMANYREFS:
  170. usMsgNum = IDS_WSAETOOMANYREFS;
  171. break;
  172. default:
  173. return(0);
  174. }
  175. if (hWinStrm == NULL)
  176. hWinStrm = GetModuleHandle( "winstrm" );
  177. if (!(msglen = FormatMessageW(
  178. FORMAT_MESSAGE_FROM_HMODULE,
  179. (LPVOID)hWinStrm,
  180. usMsgNum,
  181. 0L,
  182. perrW,
  183. MAX_MSGTABLE,
  184. NULL)))
  185. return(0);
  186. WideCharToMultiByte(CP_OEMCP,
  187. 0,
  188. perrW,
  189. -1,
  190. perr,
  191. sizeof(perr),
  192. NULL,
  193. NULL);
  194. fprintf(stderr, "-> %s:%s\n", yourmsg, perr);
  195. return(1);
  196. }