convert uses of strcasecmp to STRCASEEQ
[libguestfs.git] / hivex / hivex.c
index 16be753..8ea2c2b 100644 (file)
  * See file LICENSE for the full license.
  */
 
+#include <config.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
-#include <endian.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
 #include <iconv.h>
 #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
+
+#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"
 
@@ -230,6 +270,8 @@ hivex_open (const char *filename, int flags)
   }
 
   h->bitmap = calloc (1 + h->size / 32, 1);
+  if (h->bitmap == NULL)
+    goto error;
 
 #if 0                           /* Doesn't work. */
   /* Header checksum. */
@@ -683,7 +725,7 @@ hivex_node_get_child (hive_h *h, hive_node_h node, const char *nname)
   for (i = 0; children[i] != 0; ++i) {
     name = hivex_node_name (h, children[i]);
     if (!name) goto error;
-    if (strcasecmp (name, nname) == 0) {
+    if (STRCASEEQ (name, nname)) {
       ret = children[i];
       break;
     }
@@ -814,7 +856,7 @@ hivex_node_get_value (hive_h *h, hive_node_h node, const char *key)
   for (i = 0; values[i] != 0; ++i) {
     name = hivex_value_key (h, values[i]);
     if (!name) goto error;
-    if (strcasecmp (name, key) == 0) {
+    if (STRCASEEQ (name, key)) {
       ret = values[i];
       break;
     }
@@ -990,9 +1032,12 @@ windows_utf16_to_utf8 (/* const */ char *input, size_t len)
   size_t r = iconv (ic, &inp, &inlen, &outp, &outlen);
   if (r == (size_t) -1) {
     if (errno == E2BIG) {
+      size_t prev = outalloc;
       /* Try again with a larger output buffer. */
       free (out);
       outalloc *= 2;
+      if (outalloc < prev)
+        return NULL;
       goto again;
     }
     else {