aboutsummaryrefslogtreecommitdiff
path: root/include/stdio.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/stdio.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/stdio.h')
-rw-r--r--include/stdio.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h
index 989b7fc..ab17883 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -14,4 +14,17 @@ int vasprintf(char **str, const char *fmt, va_list ap);
14int asprintf(char **str, const char *fmt, ...); 14int asprintf(char **str, const char *fmt, ...);
15#endif 15#endif
16 16
17#ifdef _WIN32
18#include <errno.h>
19#include <string.h>
20
21static inline void
22posix_perror(const char *s)
23{
24 fprintf(stderr, "%s: %s\n", s, strerror(errno));
25}
26
27#define perror(errnum) posix_perror(errnum)
28#endif
29
17#endif 30#endif