Index: trunk/include/samhain.h
===================================================================
--- trunk/include/samhain.h	(revision 134)
+++ trunk/include/samhain.h	(revision 138)
@@ -43,6 +43,4 @@
 #define SH_PATHBUF      256
 
-#define SH_GRBUF_SIZE  4096
-#define SH_PWBUF_SIZE  4096
 #define SH_ERRBUF_SIZE   64
 
Index: trunk/include/sh_files.h
===================================================================
--- trunk/include/sh_files.h	(revision 134)
+++ trunk/include/sh_files.h	(revision 138)
@@ -30,8 +30,11 @@
 void kill_sh_dirlist (struct sh_dirent * dirlist);
 
+#ifdef NEED_ADD_DIRENT
 /* add an entry to a directory listing
  */
 struct sh_dirent * addto_sh_dirlist (struct dirent * thisEntry, 
 				     struct sh_dirent * dirlist);
+#endif
+
 /* register exceptions to hardlink check
  */
Index: trunk/include/sh_pthread.h
===================================================================
--- trunk/include/sh_pthread.h	(revision 134)
+++ trunk/include/sh_pthread.h	(revision 138)
@@ -5,4 +5,5 @@
 
 #include <pthread.h>
+
 #define SH_MUTEX(M)				pthread_mutex_t M
 #define SH_MUTEX_INIT(M,I)			pthread_mutex_t M = I
@@ -10,13 +11,18 @@
 #define SH_MUTEX_EXTERN(M)			extern pthread_mutex_t M
 
+/* pthread_mutex_unlock() has the wrong type (returns int), so
+ * we need to wrap it in this function.
+ */
+extern void sh_pthread_mutex_unlock (void *arg);
+
 #define SH_MUTEX_LOCK(M)						   \
 	do {                                                               \
                 int oldtype;                                               \
 		pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);  \
-                pthread_cleanup_push(pthread_mutex_unlock, (void *) &(M)); \
+                pthread_cleanup_push(sh_pthread_mutex_unlock, (void*)&(M));\
                 pthread_mutex_lock(&(M))
 
 
-#define SH_MUTEX_UNLOCK(M,C)						   \
+#define SH_MUTEX_UNLOCK(M)						   \
 		pthread_cleanup_pop(1);                                    \
                 pthread_setcanceltype(oldtype, NULL);                      \
@@ -26,4 +32,80 @@
 #define SH_MUTEX_UNLOCK_UNSAFE(M) pthread_mutex_unlock(&(M))
 
+
+/*
+ * ----   Recursive mutex  ----
+ */
+#if defined(PTHREAD_MUTEX_RECURSIVE)
+
+/* On GNU C, it's an enum, thus the alternative implementation 
+ * below is used.
+ */
+#define SH_MUTEX_RECURSIVE(M)                                          \
+static pthread_mutex_t M;                                              \
+static void M ## _init (void)                                          \
+{                                                                      \
+  pthread_mutexattr_t   mta;                                           \
+  pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);            \
+  pthread_mutex_init(&(M), &mta);                                      \
+  pthread_mutexattr_destroy(&mta);                                     \
+  return;                                                              \
+}                                                                      \
+static pthread_once_t  M ## _initialized = PTHREAD_ONCE_INIT
+
+#define SH_MUTEX_RECURSIVE_INIT(M)                                     \
+(void) pthread_once(&(M ## _initialized), (M ## _init))
+
+#define SH_MUTEX_RECURSIVE_LOCK(M)					   \
+	do {                                                               \
+                int oldtype;                                               \
+		pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);  \
+                pthread_cleanup_push(sh_pthread_mutex_unlock, (void*)&(M));\
+                pthread_mutex_lock(&(M))
+
+#define SH_MUTEX_RECURSIVE_UNLOCK(M)					   \
+		pthread_cleanup_pop(1);                                    \
+                pthread_setcanceltype(oldtype, NULL);                      \
+	} while (0)
+
+#else
+/* !defined(PTHREAD_MUTEX_RECURSIVE) */
+ struct sh_RMutex {
+
+  pthread_mutex_t lock;
+  unsigned int    held;
+  unsigned int    waiters;
+  pthread_t       tid;
+  pthread_cond_t  cv;
+};
+
+void sh_RMutexLock(struct sh_RMutex * tok);
+void sh_RMutexUnlock(void * arg);
+void sh_InitRMutex(struct sh_RMutex * tok);
+
+#define SH_MUTEX_RECURSIVE(M)                                          \
+static struct sh_RMutex M;                                             \
+static void M ## _init (void)                                          \
+{                                                                      \
+  sh_InitRMutex(&(M));                                                 \
+  return;                                                              \
+}                                                                      \
+static pthread_once_t  M ## _initialized = PTHREAD_ONCE_INIT
+
+#define SH_MUTEX_RECURSIVE_INIT(M)                                     \
+(void) pthread_once(&(M ## _initialized), (M ## _init))
+
+#define SH_MUTEX_RECURSIVE_LOCK(M)					   \
+	do {                                                               \
+                int oldtype;                                               \
+		pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);  \
+                pthread_cleanup_push(sh_RMutexUnlock, (void*)&(M));        \
+                sh_RMutexLock(&(M))
+
+#define SH_MUTEX_RECURSIVE_UNLOCK(M)					   \
+		pthread_cleanup_pop(1);                                    \
+                pthread_setcanceltype(oldtype, NULL);                      \
+	} while (0)
+
+#endif
 /* 
  * ----   Global mutexes   ----
@@ -32,4 +114,5 @@
 SH_MUTEX_EXTERN(mutex_resolv);
 SH_MUTEX_EXTERN(mutex_pwent);
+SH_MUTEX_EXTERN(mutex_readdir);
 
 /*
@@ -49,4 +132,9 @@
 #define SH_MUTEX_UNLOCK_UNSAFE(M)		((void)0)
 
+#define SH_MUTEX_RECURSIVE(M)                   extern void *SH_MUTEX_DUMMY_ ## M
+#define SH_MUTEX_RECURSIVE_INIT(M)              ((void)0)
+#define SH_MUTEX_RECURSIVE_LOCK(M)		((void)0)
+#define SH_MUTEX_RECURSIVE_UNLOCK(M)		((void)0)
+
 /* #ifdef HAVE_PTHREAD */
 #endif
Index: trunk/include/sh_tiger.h
===================================================================
--- trunk/include/sh_tiger.h	(revision 134)
+++ trunk/include/sh_tiger.h	(revision 138)
@@ -9,8 +9,9 @@
 typedef long int TigerType;
 
-#define TIGER_FILE -1;
-#define TIGER_DATA -2;
+#define TIGER_FILE -1
+#define TIGER_DATA -2
 
 /****************
+typedef long int TigerType;
 typedef enum {
   TIGER_FILE,
@@ -24,6 +25,6 @@
 /* the checksum function
  */
-/*@owned@*/ char * sh_tiger_hash (const char * filename, TigerType what, 
-				  UINT64 Length, char * out, size_t len);
+char * sh_tiger_hash (const char * filename, TigerType what, 
+		      UINT64 Length, char * out, size_t len);
 
 /* NEW Thu Oct 18 19:59:08 CEST 2001
Index: trunk/include/sh_utils.h
===================================================================
--- trunk/include/sh_utils.h	(revision 134)
+++ trunk/include/sh_utils.h	(revision 138)
@@ -58,5 +58,5 @@
  *  generator. 
  */
-UINT32 taus_get            (void *state1, void *state2, void *state3);  
+UINT32 taus_get            ();  
 double taus_get_double     (void *vstate);  /* fast */
 int    taus_seed           (void);
@@ -85,5 +85,6 @@
  */
 char * sh_util_siggen (char * hexkey,  
-		       char * text, size_t textlen);
+		       char * text, size_t textlen, 
+		       char * sigbuf, size_t sigbuflen);
 
 /* eval boolean input
@@ -112,7 +113,7 @@
 int sh_util_obscure_ok (const char * str);
 
-/* output a hexchar[2]
+/* output a hexchar[2]; i2h must be char[2]
  */
-char * sh_util_charhex( unsigned char c );
+char * sh_util_charhex( unsigned char c, char * i2h );
 
 /* read a hexchar, return int value (0-15)
Index: trunk/include/slib.h
===================================================================
--- trunk/include/slib.h	(revision 134)
+++ trunk/include/slib.h	(revision 138)
@@ -60,4 +60,6 @@
 #define SL_FALSE 0
 
+#define SH_GRBUF_SIZE  4096
+#define SH_PWBUF_SIZE  4096
 
 
