Treat razor data files as binary consistently
authorJ. Ali Harlow <ali@juiblex.co.uk>
Mon, 12 Jan 2009 17:54:13 +0000 (17:54 +0000)
committerJ. Ali Harlow <ali@juiblex.co.uk>
Mon, 12 Jan 2009 17:54:13 +0000 (17:54 +0000)
librazor/razor.c
librazor/root.c
librazor/rpm.c
src/main.c

index 974c92e..ee80b0a 100644 (file)
 #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;
 
index d06bca4..32d01c8 100644 (file)
 #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");
index 740eaf3..7613b54 100644 (file)
 #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;
index 843754c..6d9eae0 100644 (file)
@@ -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);