-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsstrerror.c
142 lines (132 loc) · 4.78 KB
/
wsstrerror.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// wsstrerror.c
//
// Time-stamp: <31/01/01 21:23:13 keuchel@lightning>
#include <windows.h>
#include <winsock.h>
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include "celib.h"
#define _E(x,y) {x, y}
static struct {
int code;
char *txt;
} errtab[] = {
/* windows errors */
_E(ERROR_SUCCESS, "No error"),
_E(ERROR_INVALID_FUNCTION, "Invalid function"),
_E(ERROR_FILE_NOT_FOUND, "File not found"),
_E(ERROR_PATH_NOT_FOUND, "Path not found"),
_E(ERROR_TOO_MANY_OPEN_FILES, "Too many open files"),
_E(ERROR_ACCESS_DENIED, "Access denied"),
_E(ERROR_INVALID_HANDLE, "Invalid handle"),
_E(ERROR_INVALID_ACCESS, "Invalid access"),
_E(ERROR_INVALID_DATA, "Invalid data"),
_E(ERROR_NOT_ENOUGH_MEMORY, "Out of memory"),
_E(ERROR_WRITE_PROTECT, "Write protected"),
_E(ERROR_HANDLE_EOF, "Handle EOF"),
_E(ERROR_NOT_SUPPORTED, "Operation not supported"),
_E(ERROR_FILE_EXISTS, "File exists"),
_E(ERROR_BROKEN_PIPE, "Broken pipe"),
_E(ERROR_OPEN_FAILED, "Open failed"),
_E(ERROR_DISK_FULL, "No space left on device"),
_E(ERROR_DIR_NOT_EMPTY, "Directory not empty"),
_E(ERROR_NO_DATA, "No data available"),
_E(ERROR_MORE_DATA, "More data available"),
/* winsock */
_E(WSAEINTR, "Interupted system call"),
_E(WSAEBADF, "Bad file number"),
_E(WSAEACCES, "Access denied"),
_E(WSAEFAULT, "EFAULT returned"),
_E(WSAEINVAL, "Invalid argument"),
_E(WSAEMFILE, "EMFILE returned"),
_E(WSAEWOULDBLOCK, "Operation would block"),
_E(WSAEINPROGRESS, "Operation now in progress"),
_E(WSAEALREADY, "Operation already in progress"),
_E(WSAENOTSOCK, "Socket operation on non-socket"),
_E(WSAEDESTADDRREQ, "Destination address required"),
_E(WSAEMSGSIZE, "Message too long"),
_E(WSAEPROTOTYPE, "EPROTOTYPE returned"),
_E(WSAENOPROTOOPT, "Bad protocol option"),
_E(WSAEPROTONOSUPPORT, "Protocol not supported"),
_E(WSAESOCKTNOSUPPORT, "Socket type not supported"),
_E(WSAEOPNOTSUPP, "Bad option"),
_E(WSAEPFNOSUPPORT, "Protocol family not supported"),
_E(WSAEAFNOSUPPORT, "Address family not supported by protocol family"),
_E(WSAEADDRINUSE, "Address already in use"),
_E(WSAEADDRNOTAVAIL, "Can't assign requested address"),
_E(WSAENETDOWN, "Network is down"),
_E(WSAENETUNREACH, "Network is unreachable"),
_E(WSAENETRESET, "Network was reset"),
_E(WSAECONNABORTED, "Software caused connection abort"),
_E(WSAECONNRESET, "Connection reset by peer"),
_E(WSAENOBUFS, "No buffer space is supported"),
_E(WSAEISCONN, "Socket is already connected"),
_E(WSAENOTCONN, "Socket is not connected"),
_E(WSAESHUTDOWN, "Connection shut down"),
_E(WSAETOOMANYREFS, "Too many references"),
_E(WSAETIMEDOUT, "Connection timed out"),
_E(WSAECONNREFUSED, "Connection refused"),
_E(WSAELOOP, "Loop detected"),
_E(WSAENAMETOOLONG, "Name too long"),
_E(WSAEHOSTDOWN, "Host down"),
_E(WSAEHOSTUNREACH, "Host unreachable"),
_E(WSAENOTEMPTY, "Directory not empty"),
_E(WSAEPROCLIM, "EPROCLIM returned"),
_E(WSAEUSERS, "EUSERS returned"),
_E(WSAEDQUOT, "Disk quota exceeded"),
_E(WSAESTALE, "ESTALE returned"),
_E(WSAEREMOTE, "Object is remote"),
_E(WSAEDISCON, "Disconnected"),
_E(WSASYSNOTREADY, "System not ready"),
_E(WSAVERNOTSUPPORTED, "Version is not supported"),
_E(WSANOTINITIALISED, "Sockets library not initialized"),
/* + 1001 */
_E(WSAHOST_NOT_FOUND, "Host not found"),
_E(WSATRY_AGAIN, "Host not found"),
_E(WSANO_DATA, "Host not found"),
-1, NULL
};
char *
xcewsstrerror(int code)
{
int i;
static char buf[100];
for(i = 0; errtab[i].code != -1; i++)
if(errtab[i].code == code)
return errtab[i].txt;
sprintf(buf, "Error %d\n", code);
return buf;
}
void
xcewserror(char *fmt, ...)
{
int code = WSAGetLastError();
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, ": %s\n", xcewsstrerror(code));
va_end(ap);
}
char *
xcewinstrerror(int code)
{
int i;
static char buf[100];
for(i = 0; errtab[i].code != -1; i++)
if(errtab[i].code == code)
return errtab[i].txt;
sprintf(buf, "Error %d\n", code);
return buf;
}
void
xcewinperror(char *fmt, ...)
{
int code = GetLastError();
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, ": %s\n", xcewinstrerror(code));
va_end(ap);
}