e83c30c158
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.
31 lines
514 B
C
31 lines
514 B
C
/*
|
|
* Public domain
|
|
* stdio.h compatibility shim
|
|
*/
|
|
|
|
#include_next <stdio.h>
|
|
|
|
#ifndef LIBCRYPTOCOMPAT_STDIO_H
|
|
#define LIBCRYPTOCOMPAT_STDIO_H
|
|
|
|
#ifndef HAVE_ASPRINTF
|
|
#include <stdarg.h>
|
|
int vasprintf(char **str, const char *fmt, va_list ap);
|
|
int asprintf(char **str, const char *fmt, ...);
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
|
|
static inline void
|
|
posix_perror(const char *s)
|
|
{
|
|
fprintf(stderr, "%s: %s\n", s, strerror(errno));
|
|
}
|
|
|
|
#define perror(errnum) posix_perror(errnum)
|
|
#endif
|
|
|
|
#endif
|