summaryrefslogtreecommitdiff
path: root/include/string.h
diff options
context:
space:
mode:
authorBrent Cook <busterb@gmail.com>2014-11-20 07:32:15 -0600
committerBrent Cook <bcook@openbsd.org>2014-12-03 17:07:17 -0600
commite83c30c158d8ece1e4b0f459faccfd5e5ae67112 (patch)
tree663dc024cbc2ce527614f1d38715730bef734fbc /include/string.h
parentcccdd689e39b51af02b156229e5236a2a69dcdcb (diff)
downloadportable-e83c30c158d8ece1e4b0f459faccfd5e5ae67112.tar.gz
portable-e83c30c158d8ece1e4b0f459faccfd5e5ae67112.tar.bz2
portable-e83c30c158d8ece1e4b0f459faccfd5e5ae67112.zip
monkey patch more POSIX-like behavior out of winsock 2
Windows sockets functions look on the outside like they behave similarly to POSIX functions, but there are many subtle and glaring differences, including errors reported via WSAGetLastError, read, write, and close do not work on sockets, setsockopt takes a (char *) rather than (void *), etc. This header implements wrappers that coerce more POSIX-like behavior from these functions, making portable code easier to develop. BENEFITS: One does not necessarily need to sprinkle #ifdefs around code to handle the Windows and non-Windows behavior when porting code. CAVEATS: There may be performance implications with the 'mother-may-I' approach to determining if a descriptor is a socket or a file. The errno mappings are not 100% what one might expect compared to POSIX since there were not always good 1:1 equivalents from the WSA errors.
Diffstat (limited to 'include/string.h')
-rw-r--r--include/string.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/string.h b/include/string.h
index a3263e7..c558a90 100644
--- a/include/string.h
+++ b/include/string.h
@@ -50,4 +50,20 @@ void * memmem(const void *big, size_t big_len, const void *little,
50 size_t little_len); 50 size_t little_len);
51#endif 51#endif
52 52
53#ifdef _WIN32
54#include <errno.h>
55
56static inline char *
57posix_strerror(int errnum)
58{
59 if (errnum == ECONNREFUSED) {
60 return "Connection refused";
61 }
62 return strerror(errnum);
63}
64
65#define strerror(errnum) posix_strerror(errnum)
66
67#endif
68
53#endif 69#endif