Daniel Gillen
2013-Jun-27 21:29 UTC
[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!
Richard W.M. Jones
2013-Jun-28 07:39 UTC
Re: [Libguestfs] [PATCH] hivex: Add O_BINARY flag to open calls for platforms where this isn't the default (such as Win32)
On Thu, Jun 27, 2013 at 11:29:28PM +0200, Daniel Gillen wrote:> 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;Thanks - I've pushed this. I don't know *how* it works on Linux. I can't find O_BINARY in any header at all ... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Richard W.M. Jones
2013-Jun-28 07:43 UTC
Re: [Libguestfs] [PATCH] hivex: Add O_BINARY flag to open calls for platforms where this isn't the default (such as Win32)
On Fri, Jun 28, 2013 at 08:39:44AM +0100, Richard W.M. Jones wrote:> I don't know *how* it works on Linux. I can't find O_BINARY in any > header at all ...OK, I see that gnulib is providing it. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Maybe Matching Threads
- Re: [PATCH] hivex: Add O_BINARY flag to open calls for platforms where this isn't the default (such as Win32)
- [PATCH] open O_TEXT and O_BINARY for cygwin/windows
- Please test rsync-2.5.6pre2
- [PATCH 0/3] hivex: Improve OS X support
- [PATCH] rsync on cygwin - textmode config files