Index: trunk/Makefile
===================================================================
--- trunk/Makefile	(revision 141)
+++ trunk/Makefile	(revision 143)
@@ -15,8 +15,18 @@
 INC=-I/usr/local/include
 LIB=-L/usr/local/lib -lm
+BIN_EXT=
+EXTRA_OBJ=
 
 UNAME := $(shell uname)
 ifneq ($(UNAME),Linux) 	
   LIB:=$(LIB) -liconv
+endif
+
+ifdef BUILD_MINGW
+CC=i586-mingw32msvc-cc
+BIN_EXT=.exe
+LIBICONV_PATH=/usr/local/src/libiconv-1.9.2-1-lib
+INC:=$(INC) -I$(LIBICONV_PATH)/include
+EXTRA_OBJ=$(LIBICONV_PATH)/lib/libiconv.dll.a
 endif
 
Index: trunk/include/regfi.h
===================================================================
--- trunk/include/regfi.h	(revision 141)
+++ trunk/include/regfi.h	(revision 143)
@@ -58,4 +58,11 @@
 #define REGFI_MSG_WARN  0x0004
 #define REGFI_MSG_ERROR 0x0010
+
+/* Windows is lame */
+#ifdef O_BINARY
+#define REGFI_OPEN_FLAGS O_RDONLY|O_BINARY
+#else
+#define REGFI_OPEN_FLAGS O_RDONLY
+#endif
 
 /* Registry data types */
Index: trunk/lib/regfi.c
===================================================================
--- trunk/lib/regfi.c	(revision 141)
+++ trunk/lib/regfi.c	(revision 143)
@@ -510,4 +510,10 @@
   ret_val = regfi_load_subkeylist_aux(file, offset, max_size, strict, 
 				      REGFI_MAX_SUBKEY_DEPTH);
+  if(ret_val == NULL)
+  {
+    regfi_add_message(file, REGFI_MSG_WARN, "Failed to load subkey list at"
+		      " offset 0x%.8X.", offset);
+    return NULL;
+  }
 
   if(num_keys != ret_val->num_keys)
@@ -1152,7 +1158,7 @@
 
   /* open an existing file */
-  if ((fd = open(filename, O_RDONLY)) == -1) 
-  {
-    /* DEBUG(0,("regfi_open: failure to open %s (%s)\n", filename, strerror(errno)));*/
+  if ((fd = open(filename, REGFI_OPEN_FLAGS)) == -1)
+  {
+    /* fprintf(stderr, "regfi_open: failure to open %s (%s)\n", filename, strerror(errno));*/
     return NULL;
   }
@@ -1170,5 +1176,5 @@
   if ((rb = regfi_parse_regf(fd, true)) == NULL) 
   {
-    /* DEBUG(0,("regfi_open: Failed to read initial REGF block\n"));*/
+    /* fprintf(stderr, "regfi_open: Failed to read initial REGF block\n"); */
     close(fd);
     return NULL;
@@ -1179,4 +1185,5 @@
   if(rb->hbins == NULL)
   {
+    /* fprintf(stderr, "regfi_open: Failed to create HBIN list.\n"); */
     range_list_free(rb->hbins);
     close(fd);
@@ -1331,6 +1338,5 @@
    * caching and make things slow.
    */
-  ret_val->sk_recs = lru_cache_create(127, 0x15DEAD05^time(NULL)
-				           ^(getpid()<<16)^(getppid()<<8),
+  ret_val->sk_recs = lru_cache_create(127, 0x15DEAD05^time(NULL)^(getpid()<<16),
 				      true);
 
Index: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile	(revision 141)
+++ trunk/src/Makefile	(revision 143)
@@ -3,6 +3,6 @@
 ################################################################################
 
-REGLOOKUP=$(BUILD_BIN)/reglookup
-REGLOOKUP_RECOVER=$(BUILD_BIN)/reglookup-recover
+REGLOOKUP=$(BUILD_BIN)/reglookup$(BIN_EXT)
+REGLOOKUP_RECOVER=$(BUILD_BIN)/reglookup-recover$(BIN_EXT)
 OBJ=$(wildcard ../lib/*.o)
 FILES=$(REGLOOKUP) $(REGLOOKUP_RECOVER)
@@ -11,8 +11,8 @@
 
 $(REGLOOKUP): reglookup.o $(OBJ)
-	$(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup.o $(OBJ)
+	$(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup.o $(OBJ) $(EXTRA_OBJ)
 
 $(REGLOOKUP_RECOVER): reglookup-recover.o $(OBJ)
-	$(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup-recover.o $(OBJ)
+	$(CC) $(CFLAGS) $(OPTS) $(LIB) -o $@ reglookup-recover.o $(OBJ) $(EXTRA_OBJ)
 
 reglookup.o: reglookup.c
Index: trunk/src/common.c
===================================================================
--- trunk/src/common.c	(revision 141)
+++ trunk/src/common.c	(revision 143)
@@ -31,4 +31,10 @@
 #define REGLOOKUP_VERSION "0.10.0"
 
+#define REGLOOKUP_EXIT_OK       0
+#define REGLOOKUP_EXIT_OSERR   71
+#define REGLOOKUP_EXIT_USAGE   64
+#define REGLOOKUP_EXIT_DATAERR 65
+#define REGLOOKUP_EXIT_NOINPUT 66
+
 
 void bailOut(int code, char* message)
Index: trunk/src/reglookup-recover.c
===================================================================
--- trunk/src/reglookup-recover.c	(revision 141)
+++ trunk/src/reglookup-recover.c	(revision 143)
@@ -22,5 +22,4 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <sysexits.h>
 
 #include "../include/regfi.h"
@@ -84,5 +83,5 @@
     quoted_name = malloc(1*sizeof(char));
     if(quoted_name == NULL)
-      bailOut(EX_OSERR, "ERROR: Could not allocate sufficient memory.\n");
+      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
     quoted_name[0] = '\0';
 
@@ -140,5 +139,5 @@
     quoted_name = malloc(1*sizeof(char));
     if(quoted_name == NULL)
-      bailOut(EX_OSERR, "ERROR: Could not allocate sufficient memory.\n");
+      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
     quoted_name[0] = '\0';
   }
@@ -149,5 +148,5 @@
     quoted_value = malloc(1*sizeof(char));
     if(quoted_value == NULL)
-      bailOut(EX_OSERR, "ERROR: Could not allocate sufficient memory.\n");
+      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
     quoted_value[0] = '\0';
 
@@ -714,5 +713,5 @@
   {
     usage();
-    bailOut(EX_USAGE, "ERROR: Requires at least one argument.\n");
+    bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: Requires at least one argument.\n");
   }
   
@@ -738,5 +737,5 @@
       usage();
       fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[argi]);
-      bailOut(EX_USAGE, "");
+      bailOut(REGLOOKUP_EXIT_USAGE, "");
     }
   }
@@ -744,5 +743,5 @@
 
   if((registry_file = strdup(argv[argi])) == NULL)
-    bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
+    bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");
 
   f = regfi_open(registry_file);
@@ -750,5 +749,5 @@
   {
     fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file);
-    bailOut(EX_NOINPUT, "");
+    bailOut(REGLOOKUP_EXIT_NOINPUT, "");
   }
   if(print_verbose)
Index: trunk/src/reglookup.c
===================================================================
--- trunk/src/reglookup.c	(revision 141)
+++ trunk/src/reglookup.c	(revision 143)
@@ -23,5 +23,4 @@
 
 #include <stdlib.h>
-#include <sysexits.h>
 #include <stdio.h>
 #include <string.h>
@@ -82,5 +81,5 @@
     quoted_name = malloc(1*sizeof(char));
     if(quoted_name == NULL)
-      bailOut(EX_OSERR, "ERROR: Could not allocate sufficient memory.\n");
+      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
     quoted_name[0] = '\0';
   }
@@ -161,5 +160,5 @@
       copy = (char*)malloc((next-cur+1)*sizeof(char));
       if(copy == NULL)
-	bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
+	bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");
 	  
       memcpy(copy, cur, next-cur);
@@ -169,5 +168,5 @@
 	ret_val[ret_cur] = NULL;
       else
-	bailOut(EX_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
+	bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
     }
     cur = next+1;
@@ -182,5 +181,5 @@
       ret_val[ret_cur] = NULL;
     else
-      bailOut(EX_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
+      bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
   }
 
@@ -384,5 +383,5 @@
 
   if(root == NULL)
-    bailOut(EX_DATAERR, "ERROR: root cannot be NULL.\n");
+    bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: root cannot be NULL.\n");
   
   do
@@ -392,5 +391,5 @@
       path = iter2Path(iter);
       if(path == NULL)
-	bailOut(EX_OSERR, "ERROR: Could not construct iterator's path.\n");
+	bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not construct iterator's path.\n");
 
       if(!type_filter_enabled || (key_type == type_filter))
@@ -410,5 +409,5 @@
 	{
 	  printMsgs(iter->f);
-	  bailOut(EX_DATAERR, "ERROR: could not traverse iterator upward.\n");
+	  bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: could not traverse iterator upward.\n");
 	}
 
@@ -417,5 +416,5 @@
 	{
 	  printMsgs(iter->f);
-	  bailOut(EX_DATAERR, "ERROR: unexpected NULL for key.\n");
+	  bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: unexpected NULL for key.\n");
 	}
 
@@ -431,5 +430,5 @@
       {
 	printMsgs(iter->f);
-	bailOut(EX_DATAERR, "ERROR: could not traverse iterator downward.\n");
+	bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: could not traverse iterator downward.\n");
       }
 
@@ -507,5 +506,5 @@
 
     if((value == NULL) || (tmp_path_joined == NULL))
-      bailOut(EX_OSERR, "ERROR: Unexpected error before printValue.\n");
+      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Unexpected error before printValue.\n");
 
     if(!type_filter_enabled || (value->type == type_filter))
@@ -525,5 +524,5 @@
     {
       printMsgs(iter->f);
-      bailOut(EX_DATAERR, "ERROR: Unexpected error on traversing path filter key.\n");
+      bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: Unexpected error on traversing path filter key.\n");
     }
 
@@ -568,5 +567,5 @@
   {
     usage();
-    bailOut(EX_USAGE, "ERROR: Requires at least one argument.\n");
+    bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: Requires at least one argument.\n");
   }
   
@@ -579,8 +578,8 @@
       {
 	usage();
-	bailOut(EX_USAGE, "ERROR: '-p' option requires parameter.\n");
+	bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: '-p' option requires parameter.\n");
       }
       if((path_filter = strdup(argv[argi])) == NULL)
-	bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
+	bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");
 
       path_filter_enabled = true;
@@ -591,10 +590,10 @@
       {
 	usage();
-	bailOut(EX_USAGE, "ERROR: '-t' option requires parameter.\n");
+	bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: '-t' option requires parameter.\n");
       }
       if((type_filter = regfi_type_str2val(argv[argi])) < 0)
       {
 	fprintf(stderr, "ERROR: Invalid type specified: %s.\n", argv[argi]);
-	bailOut(EX_USAGE, "");
+	bailOut(REGLOOKUP_EXIT_USAGE, "");
       }
       type_filter_enabled = true;
@@ -614,9 +613,9 @@
       usage();
       fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[argi]);
-      bailOut(EX_USAGE, "");
+      bailOut(REGLOOKUP_EXIT_USAGE, "");
     }
   }
   if((registry_file = strdup(argv[argi])) == NULL)
-    bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
+    bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");
 
   f = regfi_open(registry_file);
@@ -624,5 +623,5 @@
   {
     fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file);
-    bailOut(EX_NOINPUT, "");
+    bailOut(REGLOOKUP_EXIT_NOINPUT, "");
   }
 
@@ -632,5 +631,5 @@
   iter = regfi_iterator_new(f);
   if(iter == NULL)
-    bailOut(EX_OSERR, "ERROR: Couldn't create registry iterator.\n");
+    bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Couldn't create registry iterator.\n");
 
   if(print_header)
@@ -659,5 +658,6 @@
       fprintf(stderr, "ERROR: retrievePath() returned %d.\n", 
 	      retr_path_ret);
-      bailOut(EX_DATAERR,"ERROR: Unknown error occurred in retrieving path.\n");
+      bailOut(REGLOOKUP_EXIT_DATAERR,
+	      "ERROR: Unknown error occurred in retrieving path.\n");
     }
   }
