From 75ef5bb160fb261da1950abfd3d22f54011458e1 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Sat, 5 Dec 2015 13:58:37 -0600 Subject: [PATCH] wrap gets on Windows, replacing '\r\n' with '\n' --- crypto/compat/posix_win.c | 14 ++++++++++++++ include/compat/stdio.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/crypto/compat/posix_win.c b/crypto/compat/posix_win.c index 0dcc046..c6ff924 100644 --- a/crypto/compat/posix_win.c +++ b/crypto/compat/posix_win.c @@ -38,6 +38,20 @@ posix_fopen(const char *path, const char *mode) return fopen(path, mode); } +char * +posix_fgets(char *s, int size, FILE *stream) +{ + char *ret = fgets(s, size, stream); + if (ret != NULL) { + size_t end = strlen(ret); + if (end >= 2 && ret[end - 2] == '\r' && ret[end - 1] == '\n') { + ret[end - 2] = '\n'; + ret[end - 1] = '\0'; + } + } + return ret; +} + int posix_rename(const char *oldpath, const char *newpath) { diff --git a/include/compat/stdio.h b/include/compat/stdio.h index 4b96b8b..a0dda6f 100644 --- a/include/compat/stdio.h +++ b/include/compat/stdio.h @@ -28,11 +28,13 @@ int asprintf(char **str, const char *fmt, ...); void posix_perror(const char *s); FILE * posix_fopen(const char *path, const char *mode); +char * posix_fgets(char *s, int size, FILE *stream); int posix_rename(const char *oldpath, const char *newpath); #ifndef NO_REDEF_POSIX_FUNCTIONS #define perror(errnum) posix_perror(errnum) #define fopen(path, mode) posix_fopen(path, mode) +#define fgets(s, size, stream) posix_fgets(s, size, stream) #define rename(oldpath, newpath) posix_rename(oldpath, newpath) #endif