[Libguestfs] [PATCH 1/12] Move htole*/le*toh macros into a separate header file.

Richard W.M. Jones rjones at redhat.com
Wed Feb 3 18:31:31 UTC 2010


-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
-------------- next part --------------
>From b252683d6ddeb6976133ac33ff84c7580e5076e1 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones at redhat.com>
Date: Wed, 3 Feb 2010 17:41:15 +0000
Subject: [PATCH 01/12] Move htole*/le*toh macros into a separate header file.

This allows us to reuse these macros in hivexsh later.
---
 hivex/Makefile.am        |    3 +-
 hivex/byte_conversions.h |   89 ++++++++++++++++++++++++++++++++++++++++++++++
 hivex/hivex.c            |   43 +---------------------
 3 files changed, 93 insertions(+), 42 deletions(-)
 create mode 100644 hivex/byte_conversions.h

diff --git a/hivex/Makefile.am b/hivex/Makefile.am
index ae7dbac..1adbbd8 100644
--- a/hivex/Makefile.am
+++ b/hivex/Makefile.am
@@ -21,7 +21,8 @@ lib_LTLIBRARIES = libhivex.la
 
 libhivex_la_SOURCES = \
   hivex.c \
-  hivex.h
+  hivex.h \
+  byte_conversions.h
 
 libhivex_la_LDFLAGS = -version-info 0:0:0
 libhivex_la_CFLAGS = \
diff --git a/hivex/byte_conversions.h b/hivex/byte_conversions.h
new file mode 100644
index 0000000..84e9e2d
--- /dev/null
+++ b/hivex/byte_conversions.h
@@ -0,0 +1,89 @@
+/* Useful byte conversion macros, not available on all platforms.
+ * Copyright (C) 2009-2010 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef hivex_byteorder_h
+#define hivex_byteorder_h
+
+#ifdef HAVE_ENDIAN_H
+#include <endian.h>
+#endif
+#ifdef HAVE_BYTESWAP_H
+#include <byteswap.h>
+#endif
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef be32toh
+#define be32toh(x) __bswap_32 (x)
+#endif
+#ifndef htobe32
+#define htobe32(x) __bswap_32 (x)
+#endif
+#ifndef be64toh
+#define be64toh(x) __bswap_64 (x)
+#endif
+#ifndef htobe64
+#define htobe64(x) __bswap_64 (x)
+#endif
+#ifndef le16toh
+#define le16toh(x) (x)
+#endif
+#ifndef htole16
+#define htole16(x) (x)
+#endif
+#ifndef le32toh
+#define le32toh(x) (x)
+#endif
+#ifndef htole32
+#define htole32(x) (x)
+#endif
+#ifndef le64toh
+#define le64toh(x) (x)
+#endif
+#ifndef htole64
+#define htole64(x) (x)
+#endif
+#else /* __BYTE_ORDER == __BIG_ENDIAN */
+#ifndef be32toh
+#define be32toh(x) (x)
+#endif
+#ifndef htobe32
+#define htobe32(x) (x)
+#endif
+#ifndef be64toh
+#define be64toh(x) (x)
+#endif
+#ifndef htobe64
+#define htobe64(x) (x)
+#endif
+#ifndef le16toh
+#define le16toh(x) __bswap_16 (x)
+#endif
+#ifndef htole16
+#define htole16(x) __bswap_16 (x)
+#endif
+#ifndef le32toh
+#define le32toh(x) __bswap_32 (x)
+#endif
+#ifndef htole32
+#define htole32(x) __bswap_32 (x)
+#endif
+#ifndef le64toh
+#define le64toh(x) __bswap_64 (x)
+#endif
+#ifndef htole64
+#define htole64(x) __bswap_64 (x)
+#endif
+#endif /* __BYTE_ORDER == __BIG_ENDIAN */
+
+#endif /* hivex_byteorder_h */
diff --git a/hivex/hivex.c b/hivex/hivex.c
index d2c450f..4cf3ad9 100644
--- a/hivex/hivex.c
+++ b/hivex/hivex.c
@@ -1,5 +1,5 @@
 /* hivex - Windows Registry "hive" extraction library.
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-2010 Red Hat Inc.
  * Derived from code by Petter Nordahl-Hagen under a compatible license:
  *   Copyright (c) 1997-2007 Petter Nordahl-Hagen.
  * Derived from code by Markus Stephany under a compatible license:
@@ -33,12 +33,6 @@
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <assert.h>
-#ifdef HAVE_ENDIAN_H
-#include <endian.h>
-#endif
-#ifdef HAVE_BYTESWAP_H
-#include <byteswap.h>
-#endif
 
 #define STREQ(a,b) (strcmp((a),(b)) == 0)
 #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
@@ -50,41 +44,8 @@
 //#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
 //#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#ifndef be32toh
-#define be32toh(x) __bswap_32 (x)
-#endif
-#ifndef be64toh
-#define be64toh(x) __bswap_64 (x)
-#endif
-#ifndef le16toh
-#define le16toh(x) (x)
-#endif
-#ifndef le32toh
-#define le32toh(x) (x)
-#endif
-#ifndef le64toh
-#define le64toh(x) (x)
-#endif
-#else
-#ifndef be32toh
-#define be32toh(x) (x)
-#endif
-#ifndef be64toh
-#define be64toh(x) (x)
-#endif
-#ifndef le16toh
-#define le16toh(x) __bswap_16 (x)
-#endif
-#ifndef le32toh
-#define le32toh(x) __bswap_32 (x)
-#endif
-#ifndef le64toh
-#define le64toh(x) __bswap_64 (x)
-#endif
-#endif
-
 #include "hivex.h"
+#include "byte_conversions.h"
 
 static char *windows_utf16_to_utf8 (/* const */ char *input, size_t len);
 
-- 
1.6.5.2



More information about the Libguestfs mailing list