Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions tools/squashelf/squashelf.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
#include <stdbool.h> /* Needed for bool type */
#include "../../include/elf.h"

/* On Windows, fds default to text mode, which corrupts binary data by
* translating line endings. O_BINARY disables this; it doesn't exist on
* POSIX systems, where all I/O is already binary. */
#ifndef O_BINARY
#define O_BINARY 0
#endif

/* Macro for verbose printing */
#define DEBUG_PRINT(fmt, ...) \
do { \
Expand Down Expand Up @@ -481,7 +488,7 @@ int main(int argCount, char** argValues)
}

/* Open input ELF file for reading */
inputFd = open(inputFile, O_RDONLY);
inputFd = open(inputFile, O_RDONLY | O_BINARY);
if (inputFd < 0) {
perror("open inputFile");
goto cleanup;
Expand Down Expand Up @@ -712,7 +719,7 @@ int main(int argCount, char** argValues)
}

/* Open output file for writing */
outputFd = open(outputFile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
outputFd = open(outputFile, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
if (outputFd < 0) {
perror("open outputFile");
goto cleanup;
Expand Down
Loading