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

Richard W.M. Jones rjones at redhat.com
Fri Jun 28 07:39:44 UTC 2013


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 at 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




More information about the Libguestfs mailing list