From: J. Ali Harlow Date: Mon, 12 Jan 2009 17:54:13 +0000 (+0000) Subject: Treat razor data files as binary consistently X-Git-Tag: 0.1~33 X-Git-Url: http://project.juiblex.co.uk/git/?a=commitdiff_plain;h=e423fe0e46bae40da8ed9f1a07b588bee3c0e2d5;p=razor2.git%2F.git Treat razor data files as binary consistently --- diff --git a/librazor/razor.c b/librazor/razor.c index 974c92e..ee80b0a 100644 --- a/librazor/razor.c +++ b/librazor/razor.c @@ -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 @@ razor_set_write(struct razor_set *set, const char *filename, { 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 --git a/librazor/root.c b/librazor/root.c index d06bca4..32d01c8 100644 --- a/librazor/root.c +++ b/librazor/root.c @@ -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 @@ razor_root_open(const char *root) 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 --git a/librazor/rpm.c b/librazor/rpm.c index 740eaf3..7613b54 100644 --- a/librazor/rpm.c +++ b/librazor/rpm.c @@ -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 @@ create_path(struct installer *installer, const char *path, unsigned int mode) 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 --git a/src/main.c b/src/main.c index 843754c..6d9eae0 100644 --- a/src/main.c +++ b/src/main.c @@ -373,7 +373,7 @@ download_if_missing(const char *url, const char *file) 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);