windows: Extend strerror_r/s by extended POSIX errno strings

This commit is contained in:
Martin Willi 2014-06-11 12:07:34 +02:00
parent c2119cded4
commit 1bcf850738
2 changed files with 66 additions and 0 deletions

View File

@ -309,6 +309,66 @@ char* getpass(const char *prompt)
return buf;
}
/**
* See header.
*/
#undef strerror_s
int strerror_s_extended(char *buf, size_t buflen, int errnum)
{
const char *errstr [] = {
/* EADDRINUSE */ "Address in use",
/* EADDRNOTAVAIL */ "Address not available",
/* EAFNOSUPPORT */ "Address family not supported",
/* EALREADY */ "Connection already in progress",
/* EBADMSG */ "Bad message",
/* ECANCELED */ "Operation canceled",
/* ECONNABORTED */ "Connection aborted",
/* ECONNREFUSED */ "Connection refused",
/* ECONNRESET */ "Connection reset",
/* EDESTADDRREQ */ "Destination address required",
/* EHOSTUNREACH */ "Host is unreachable",
/* EIDRM */ "Identifier removed",
/* EINPROGRESS */ "Operation in progress",
/* EISCONN */ "Socket is connected",
/* ELOOP */ "Too many levels of symbolic links",
/* EMSGSIZE */ "Message too large",
/* ENETDOWN */ "Network is down",
/* ENETRESET */ "Connection aborted by network",
/* ENETUNREACH */ "Network unreachable",
/* ENOBUFS */ "No buffer space available",
/* ENODATA */ "No message is available",
/* ENOLINK */ "No link",
/* ENOMSG */ "No message of the desired type",
/* ENOPROTOOPT */ "Protocol not available",
/* ENOSR */ "No stream resources",
/* ENOSTR */ "Not a stream",
/* ENOTCONN */ "The socket is not connected",
/* ENOTRECOVERABLE */ "State not recoverable",
/* ENOTSOCK */ "Not a socket",
/* ENOTSUP */ "Not supported",
/* EOPNOTSUPP */ "Operation not supported on socket",
/* EOTHER */ "Other error",
/* EOVERFLOW */ "Value too large to be stored in data type",
/* EOWNERDEAD */ "Previous owner died",
/* EPROTO */ "Protocol error",
/* EPROTONOSUPPORT */ "Protocol not supported",
/* EPROTOTYPE */ "Protocol wrong type for socket",
/* ETIME */ "Timeout",
/* ETIMEDOUT */ "Connection timed out",
/* ETXTBSY */ "Text file busy",
/* EWOULDBLOCK */ "Operation would block",
};
int offset = EADDRINUSE;
if (errnum < offset || errnum > offset + countof(errstr))
{
return strerror_s(buf, buflen, errnum);
}
strncpy(buf, errstr[errnum - offset], buflen);
buf[buflen - 1] = '\0';
return 0;
}
/**
* Set errno for a function setting WSA error on failure
*/

View File

@ -361,6 +361,12 @@ ssize_t windows_send(int sockfd, const void *buf, size_t len, int flags);
ssize_t windows_sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen);
/**
* strerror_s, but supporting POSIX compatiblity errno >= 100
*/
#define strerror_s strerror_s_extended
int strerror_s_extended(char *buf, size_t buflen, int errnum);
/**
* strerror_r(2) replacement, XSI variant
*/