wrap gets on Windows, replacing '\r\n' with '\n'

This commit is contained in:
Brent Cook
2015-12-05 13:58:37 -06:00
parent d7317353a9
commit 75ef5bb160
2 changed files with 16 additions and 0 deletions

View File

@@ -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)
{