# HG changeset patch # User J. Ali Harlow # Date 1231782853 0 # Node ID edd9b0fa63caade166ee94578bc3edcff7700a86 # Parent 1b54aa2137d3a91fdb53d3d01edd59ecf6330190 Treat razor data files as binary consistently diff -r 1b54aa2137d3 -r edd9b0fa63ca librazor/razor.c --- a/librazor/razor.c Mon Jan 12 16:37:55 2009 +0000 +++ b/librazor/razor.c Mon Jan 12 17:54:13 2009 +0000 @@ -39,6 +39,10 @@ #include "razor-internal.h" #include "razor.h" +#ifndef O_BINARY +#define O_BINARY 0 +#endif + void * zalloc(size_t size) { @@ -283,7 +287,7 @@ { int fd, status; - fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666); + fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0666); if (fd < 0) return -1; diff -r 1b54aa2137d3 -r edd9b0fa63ca librazor/root.c --- a/librazor/root.c Mon Jan 12 16:37:55 2009 +0000 +++ b/librazor/root.c Mon Jan 12 17:54:13 2009 +0000 @@ -37,6 +37,10 @@ #include "razor.h" #include "razor-internal.h" +#ifndef O_BINARY +#define O_BINARY 0 +#endif + static const char system_repo_filename[] = "system.rzdb"; static const char system_repo_details_filename[] = "system-details.rzdb"; static const char system_repo_files_filename[] = "system-files.rzdb"; @@ -149,7 +153,8 @@ snprintf(image->new_path, sizeof image->new_path, "%s%s/%s", root, razor_root_path, next_repo_filename); image->fd = open(image->new_path, - O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0666); + O_CREAT | O_WRONLY | O_TRUNC | O_EXCL | O_BINARY, + 0666); if (image->fd < 0) { fprintf(stderr, "failed to get lock file, " "maybe previous operation crashed?\n"); diff -r 1b54aa2137d3 -r edd9b0fa63ca librazor/rpm.c --- a/librazor/rpm.c Mon Jan 12 16:37:55 2009 +0000 +++ b/librazor/rpm.c Mon Jan 12 17:54:13 2009 +0000 @@ -44,6 +44,10 @@ #include "razor.h" #include "razor-internal.h" +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #define RPM_LEAD_SIZE 96 enum { @@ -509,7 +513,8 @@ switch (mode >> 12) { case REG: /* FIXME: handle the case where a file is already there. */ - fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, mode & 0x1ff); + fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + mode & 0x1ff); if (fd < 0){ fprintf(stderr, "failed to create file %s\n", buffer); return -1; diff -r 1b54aa2137d3 -r edd9b0fa63ca src/main.c --- a/src/main.c Mon Jan 12 16:37:55 2009 +0000 +++ b/src/main.c Mon Jan 12 17:54:13 2009 +0000 @@ -373,7 +373,7 @@ curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, file); if (stat(file, &buf) < 0) { - fp = fopen(file, "w"); + fp = fopen(file, "wb"); if (fp == NULL) { fprintf(stderr, "failed to open %s for writing\n", file);