]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/random.c
(no commit message)
[imagemagick] / MagickCore / random.c
index 4cdf9f8fcac15b8e4a204067f2a801380d4de28a..416f9efca14878c23c826707fa505a7c3c112935 100644 (file)
 %               MagickCore Methods to Generate Random Numbers                 %
 %                                                                             %
 %                             Software Design                                 %
-%                               John Cristy                                   %
+%                                  Cristy                                     %
 %                              December 2001                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -117,8 +117,10 @@ struct _RandomInfo
 #define environ (*_NSGetEnviron())
 #endif
 
+#if !defined(MAGICKCORE_WINDOWS_SUPPORT)
 extern char
   **environ;
+#endif
 \f
 /*
   Global declarations.
@@ -192,7 +194,7 @@ MagickExport RandomInfo *AcquireRandomInfo(void)
   random_info->secret_key=secret_key;
   random_info->protocol_major=RandomProtocolMajorVersion;
   random_info->protocol_minor=RandomProtocolMinorVersion;
-  random_info->semaphore=AllocateSemaphoreInfo();
+  random_info->semaphore=AcquireSemaphoreInfo();
   random_info->timestamp=(ssize_t) time(0);
   random_info->signature=MagickSignature;
   /*
@@ -292,7 +294,7 @@ MagickExport RandomInfo *DestroyRandomInfo(RandomInfo *random_info)
   (void) ResetMagickMemory(random_info->seed,0,sizeof(*random_info->seed));
   random_info->signature=(~MagickSignature);
   UnlockSemaphoreInfo(random_info->semaphore);
-  DestroySemaphoreInfo(&random_info->semaphore);
+  RelinquishSemaphoreInfo(&random_info->semaphore);
   random_info=(RandomInfo *) RelinquishMagickMemory(random_info);
   return(random_info);
 }
@@ -448,23 +450,22 @@ static StringInfo *GenerateEntropicChaos(RandomInfo *random_info)
 #if defined(MAGICKCORE_HAVE_MKSTEMP)
   {
     char
-      *filename;
+      path[MaxTextExtent];
 
     int
       file;
 
-    filename=ConstantString("magickXXXXXX");
-    file=mkstemp(filename);
+    (void) GetPathTemplate(path);
+    file=mkstemp(path);
 #if defined(__OS2__)
     setmode(file,O_BINARY);
 #endif
     if (file != -1)
       (void) close(file);
-    (void) ShredFile(filename);
-    SetStringInfoLength(chaos,strlen(filename));
-    SetStringInfoDatum(chaos,(unsigned char *) filename);
+    (void) remove_utf8(path);
+    SetStringInfoLength(chaos,strlen(path));
+    SetStringInfoDatum(chaos,(unsigned char *) path);
     ConcatenateStringInfo(entropy,chaos);
-    filename=DestroyString(filename);
   }
 #endif
 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
@@ -737,7 +738,8 @@ MagickExport double GetRandomValue(RandomInfo *random_info)
 */
 MagickPrivate MagickBooleanType RandomComponentGenesis(void)
 {
-  AcquireSemaphoreInfo(&random_semaphore);
+  if (random_semaphore == (SemaphoreInfo *) NULL)
+    random_semaphore=AcquireSemaphoreInfo();
   return(MagickTrue);
 }
 \f
@@ -762,8 +764,8 @@ MagickPrivate MagickBooleanType RandomComponentGenesis(void)
 MagickPrivate void RandomComponentTerminus(void)
 {
   if (random_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&random_semaphore);
-  DestroySemaphoreInfo(&random_semaphore);
+    ActivateSemaphoreInfo(&random_semaphore);
+  RelinquishSemaphoreInfo(&random_semaphore);
 }
 \f
 /*
@@ -922,3 +924,15 @@ MagickExport void SetRandomTrueRandom(const MagickBooleanType true_random)
 {
   gather_true_random=true_random;
 }
+
+MagickPrivate unsigned long *GetRandomInfoSeed(RandomInfo *random_info)
+{
+  assert(random_info != (RandomInfo *) NULL);
+  return random_info->seed;
+}
+
+MagickPrivate double GetRandomInfoNormalize(RandomInfo *random_info)
+{
+  assert(random_info != (RandomInfo *) NULL);
+  return random_info->normalize;
+}