[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] hivex: Add O_BINARY flag to open calls for platforms where this isn't the default (such as Win32)



Hi

As my cross platform registry editor (FRED available from
https://www.pinguin.lu (sorry for advertising but I couldn't resist
;-))) is evolving, I recently added write support to it.

While under Linux everything worked nice, the Windblows build didn't.

It seems that Windows opens files by default in text mode (O_TEXT) which
is a problem. The attached patch adds the O_BINARY flag to all open
calls which solves the issue and allows libhivex to alter hives in Windows.

I don't think this will harm on any other platform, so no fancy ifdefs
this time :)

ok?

cu

-- 
Unix _IS_ user friendly - it's just
selective about who its friends are!
>From 726feff722dbaee93064ffc603d9979c26399928 Mon Sep 17 00:00:00 2001
From: Gillen Daniel <gillen daniel gmail com>
Date: Thu, 27 Jun 2013 23:08:15 +0200
Subject: [PATCH] hivex: Add O_BINARY flag to open calls for platforms where
 this isn't the default (such as Win32)

---
 lib/hivex.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/hivex.c b/lib/hivex.c
index 040b1e7..86e5959 100644
--- a/lib/hivex.c
+++ b/lib/hivex.c
@@ -265,9 +265,9 @@ hivex_open (const char *filename, int flags)
     goto error;
 
 #ifdef O_CLOEXEC
-  h->fd = open (filename, O_RDONLY | O_CLOEXEC);
+  h->fd = open (filename, O_RDONLY | O_CLOEXEC | O_BINARY);
 #else
-  h->fd = open (filename, O_RDONLY);
+  h->fd = open (filename, O_RDONLY | O_BINARY);
 #endif
   if (h->fd == -1)
     goto error;
@@ -2261,7 +2261,7 @@ hivex_commit (hive_h *h, const char *filename, int flags)
   }
 
   filename = filename ? : h->filename;
-  int fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY, 0666);
+  int fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_BINARY, 0666);
   if (fd == -1)
     return -1;
 
-- 
1.7.10.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]