2014-11-19 14:43:07 +01:00
|
|
|
/*
|
|
|
|
* Public domain
|
|
|
|
* stdio.h compatibility shim
|
|
|
|
*/
|
|
|
|
|
2014-07-29 02:26:15 +02:00
|
|
|
#include_next <stdio.h>
|
|
|
|
|
|
|
|
#ifndef LIBCRYPTOCOMPAT_STDIO_H
|
|
|
|
#define LIBCRYPTOCOMPAT_STDIO_H
|
|
|
|
|
2014-10-29 21:44:36 +01:00
|
|
|
#ifndef HAVE_ASPRINTF
|
2014-08-12 10:21:48 +02:00
|
|
|
#include <stdarg.h>
|
2014-07-29 02:26:15 +02:00
|
|
|
int vasprintf(char **str, const char *fmt, va_list ap);
|
|
|
|
int asprintf(char **str, const char *fmt, ...);
|
|
|
|
#endif
|
|
|
|
|
2014-11-20 14:32:15 +01:00
|
|
|
#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)
|
2015-06-05 10:31:28 +02:00
|
|
|
|
|
|
|
static inline FILE *
|
|
|
|
posix_fopen(const char *path, const char *mode)
|
|
|
|
{
|
|
|
|
char *bin_mode = mode;
|
|
|
|
if (strchr(mode, 'b') == NULL) {
|
|
|
|
bin_mode = NULL;
|
|
|
|
if (asprintf(&bin_mode, "%sb", mode) == -1)
|
|
|
|
return NULL;
|
|
|
|
fprintf(stderr, "opening bin file %s\n", bin_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *f = fopen(path, bin_mode);
|
|
|
|
if (bin_mode != mode)
|
|
|
|
free(bin_mode);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define fopen(path, mode) posix_fopen(path, mode)
|
|
|
|
|
2014-11-20 14:32:15 +01:00
|
|
|
#endif
|
|
|
|
|
2014-07-29 02:26:15 +02:00
|
|
|
#endif
|