From 63991de5dc75eabab667541ec5805a375486cf20 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Sun, 15 Dec 2024 20:33:41 +0100 Subject: [PATCH] fix: fopen for fwrite use binary mode this avoids adding a carriage return on windows --- src/muntar.c | 4 ++-- test/muntar.bats | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/muntar.c b/src/muntar.c index 09f89bf..3b52871 100644 --- a/src/muntar.c +++ b/src/muntar.c @@ -157,11 +157,11 @@ static int mtar_rewind(mtar_t *tar) { /////////////////// -#include // for mkdir(2) #if defined(_WIN32) #include #define makedir(path) CreateDirectory(path, NULL) #else +#include #define makedir(path) mkdir(path,0755) #endif // used by extract_embeddings(char *tmpdir) @@ -219,7 +219,7 @@ int untar_to_path(const char *path, const uint8_t *buf, const size_t namelen = strlen(header->name); if(p-tpath+namelen>1023) return(MTAR_EOPENFAIL); strcpy(p,header->name); - FILE *fp = fopen(tpath,"w"); + FILE *fp = fopen(tpath,"wb"); if(!fp) { fprintf(stderr, "Error open file for write: %s\n", diff --git a/test/muntar.bats b/test/muntar.bats index e78c344..dcb1324 100644 --- a/test/muntar.bats +++ b/test/muntar.bats @@ -95,7 +95,7 @@ int main(int argc, char **argv) { free(dest); exit(res); } - FILE *fp = fopen("examples_uncompressed.tar","w"); + FILE *fp = fopen("examples_uncompressed.tar","wb"); if(!fp) { fprintf(stderr, "Error open file for write: %s\n",