Resolve clash between stdint.m4 and uintmax_t.m4.
[gnulib.git] / lib / gc-gnulib.c
index 61143b0..a91a7c3 100644 (file)
@@ -1,5 +1,5 @@
-/* gc-gl-common.c --- Common gnulib internal crypto interface functions
- * Copyright (C) 2002, 2003, 2004, 2005  Simon Josefsson
+/* gc-gnulib.c --- Common gnulib internal crypto interface functions
+ * Copyright (C) 2002, 2003, 2004, 2005, 2006  Simon Josefsson
  *
  * This file is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
 #include <string.h>
 
 /* For randomize. */
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
+#ifdef GC_USE_RANDOM
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/stat.h>
+# include <fcntl.h>
+# include <errno.h>
+#endif
 
 /* Hashes. */
 #ifdef GC_USE_MD2
@@ -80,6 +82,8 @@ gc_done (void)
   return;
 }
 
+#ifdef GC_USE_RANDOM
+
 /* Randomness. */
 
 static Gc_rc
@@ -105,6 +109,9 @@ randomize (int level, char *data, size_t datalen)
       break;
     }
 
+  if (strcmp (device, "no") == 0)
+    return GC_RANDOM_ERROR;
+
   fd = open (device, O_RDONLY);
   if (fd < 0)
     return GC_RANDOM_ERROR;
@@ -152,6 +159,8 @@ gc_random (char *data, size_t datalen)
   return randomize (2, data, datalen);
 }
 
+#endif
+
 /* Memory allocation. */
 
 void
@@ -192,6 +201,8 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
   Gc_rc rc = GC_OK;
 
   ctx = calloc (sizeof (*ctx), 1);
+  if (!ctx)
+    return GC_MALLOC_ERROR;
 
   ctx->alg = alg;
   ctx->mode = mode;