Skip to content

Commit

Permalink
fix: fopen for fwrite use binary mode
Browse files Browse the repository at this point in the history
this avoids adding a carriage return on windows
  • Loading branch information
jaromil committed Dec 15, 2024
1 parent fcad0d7 commit 63991de
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/muntar.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ static int mtar_rewind(mtar_t *tar) {
///////////////////


#include <sys/stat.h> // for mkdir(2)
#if defined(_WIN32)
#include <windows.h>
#define makedir(path) CreateDirectory(path, NULL)
#else
#include <sys/stat.h>
#define makedir(path) mkdir(path,0755)
#endif
// used by extract_embeddings(char *tmpdir)
Expand Down Expand Up @@ -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);

Check warning on line 221 in src/muntar.c

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] src/muntar.c#L221

Almost always, snprintf is better than strcpy [runtime/printf] [4]
Raw output
src/muntar.c:221:  Almost always, snprintf is better than strcpy  [runtime/printf] [4]
FILE *fp = fopen(tpath,"w");
FILE *fp = fopen(tpath,"wb");
if(!fp) {
fprintf(stderr,
"Error open file for write: %s\n",
Expand Down
2 changes: 1 addition & 1 deletion test/muntar.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 63991de

Please sign in to comment.