Cygwin: clean error mapping
- Move definition of windows to POSIX error mapping struct into cygerrno.h - Move declaration of winsock errno functions to cygerrno.h - Input to error mapping functions is DWORD Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
		
							parent
							
								
									0a3f4e6087
								
							
						
					
					
						commit
						044ab77dcc
					
				|  | @ -11,6 +11,13 @@ details. */ | ||||||
| #include <errno.h> | #include <errno.h> | ||||||
| #include "regparm.h" | #include "regparm.h" | ||||||
| 
 | 
 | ||||||
|  | struct errmap_t | ||||||
|  | { | ||||||
|  |   DWORD w;		 /* windows version of error */ | ||||||
|  |   const char *s;	 /* text of windows version */ | ||||||
|  |   int e;		 /* errno version of error */ | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| void __reg3 seterrno_from_win_error (const char *file, int line, DWORD code); | void __reg3 seterrno_from_win_error (const char *file, int line, DWORD code); | ||||||
| void __reg3 seterrno_from_nt_status (const char *file, int line, NTSTATUS status); | void __reg3 seterrno_from_nt_status (const char *file, int line, NTSTATUS status); | ||||||
| int __reg2 geterrno_from_win_error (DWORD code = GetLastError (), int deferrno = 13 /*EACCESS*/); | int __reg2 geterrno_from_win_error (DWORD code = GetLastError (), int deferrno = 13 /*EACCESS*/); | ||||||
|  | @ -34,6 +41,9 @@ __set_errno (const char *fn, int ln, int val) | ||||||
| } | } | ||||||
| #define set_errno(val) __set_errno (__PRETTY_FUNCTION__, __LINE__, (val)) | #define set_errno(val) __set_errno (__PRETTY_FUNCTION__, __LINE__, (val)) | ||||||
| 
 | 
 | ||||||
|  | void __reg2 __set_winsock_errno (const char *fn, int ln); | ||||||
|  | #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__) | ||||||
|  | 
 | ||||||
| #define get_errno()  (errno) | #define get_errno()  (errno) | ||||||
| extern "C" void __stdcall set_sig_errno (int e); | extern "C" void __stdcall set_sig_errno (int e); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -31,12 +31,7 @@ details. */ | ||||||
| 
 | 
 | ||||||
| #define X(w, e) {ERROR_##w, #w, e} | #define X(w, e) {ERROR_##w, #w, e} | ||||||
| 
 | 
 | ||||||
| static const struct | static const errmap_t errmap[] = | ||||||
| { |  | ||||||
|   DWORD w;		 /* windows version of error */ |  | ||||||
|   const char *s;	 /* text of windows version */ |  | ||||||
|   int e;		 /* errno version of error */ |  | ||||||
| } errmap[] = |  | ||||||
| { | { | ||||||
|   /* FIXME: Some of these choices are arbitrary! */ |   /* FIXME: Some of these choices are arbitrary! */ | ||||||
|   X (ACCESS_DENIED,		EACCES), |   X (ACCESS_DENIED,		EACCES), | ||||||
|  |  | ||||||
|  | @ -150,14 +150,7 @@ inet_makeaddr (int net, int lna) | ||||||
|   return in; |   return in; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| struct tl | static const errmap_t wsock_errmap[] = { | ||||||
| { |  | ||||||
|   int w; |  | ||||||
|   const char *s; |  | ||||||
|   int e; |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| static const struct tl errmap[] = { |  | ||||||
|   {WSA_INVALID_HANDLE, "WSA_INVALID_HANDLE", EBADF}, |   {WSA_INVALID_HANDLE, "WSA_INVALID_HANDLE", EBADF}, | ||||||
|   {WSA_NOT_ENOUGH_MEMORY, "WSA_NOT_ENOUGH_MEMORY", ENOMEM}, |   {WSA_NOT_ENOUGH_MEMORY, "WSA_NOT_ENOUGH_MEMORY", ENOMEM}, | ||||||
|   {WSA_INVALID_PARAMETER, "WSA_INVALID_PARAMETER", EINVAL}, |   {WSA_INVALID_PARAMETER, "WSA_INVALID_PARAMETER", EINVAL}, | ||||||
|  | @ -206,11 +199,11 @@ static const struct tl errmap[] = { | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| static int | static int | ||||||
| find_winsock_errno (int why) | find_winsock_errno (DWORD why) | ||||||
| { | { | ||||||
|   for (int i = 0; errmap[i].s != NULL; ++i) |   for (int i = 0; wsock_errmap[i].s != NULL; ++i) | ||||||
|     if (why == errmap[i].w) |     if (why == wsock_errmap[i].w) | ||||||
|       return errmap[i].e; |       return wsock_errmap[i].e; | ||||||
| 
 | 
 | ||||||
|   return EPERM; |   return EPERM; | ||||||
| } | } | ||||||
|  | @ -229,7 +222,7 @@ __set_winsock_errno (const char *fn, int ln) | ||||||
|  * Since the member `s' isn't used for debug output we can use it |  * Since the member `s' isn't used for debug output we can use it | ||||||
|  * for the error text returned by herror and hstrerror. |  * for the error text returned by herror and hstrerror. | ||||||
|  */ |  */ | ||||||
| static const struct tl host_errmap[] = { | static const errmap_t host_errmap[] = { | ||||||
|   {WSAHOST_NOT_FOUND, "Unknown host", HOST_NOT_FOUND}, |   {WSAHOST_NOT_FOUND, "Unknown host", HOST_NOT_FOUND}, | ||||||
|   {WSATRY_AGAIN, "Host name lookup failure", TRY_AGAIN}, |   {WSATRY_AGAIN, "Host name lookup failure", TRY_AGAIN}, | ||||||
|   {WSANO_RECOVERY, "Unknown server error", NO_RECOVERY}, |   {WSANO_RECOVERY, "Unknown server error", NO_RECOVERY}, | ||||||
|  | @ -242,7 +235,7 @@ set_host_errno () | ||||||
| { | { | ||||||
|   int i; |   int i; | ||||||
| 
 | 
 | ||||||
|   int why = WSAGetLastError (); |   DWORD why = WSAGetLastError (); | ||||||
| 
 | 
 | ||||||
|   for (i = 0; host_errmap[i].w != 0; ++i) |   for (i = 0; host_errmap[i].w != 0; ++i) | ||||||
|     if (why == host_errmap[i].w) |     if (why == host_errmap[i].w) | ||||||
|  |  | ||||||
|  | @ -212,9 +212,6 @@ bool timeval_to_ms (const struct timeval *, DWORD &); | ||||||
| void __stdcall set_console_title (char *); | void __stdcall set_console_title (char *); | ||||||
| void init_console_handler (bool); | void init_console_handler (bool); | ||||||
| 
 | 
 | ||||||
| void __reg2 __set_winsock_errno (const char *fn, int ln); |  | ||||||
| #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__) |  | ||||||
| 
 |  | ||||||
| extern bool wsock_started; | extern bool wsock_started; | ||||||
| 
 | 
 | ||||||
| /* Printf type functions */ | /* Printf type functions */ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue