]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/utility.c
(no commit message)
[imagemagick] / MagickCore / utility.c
index 6dedc601341675ea934f6809b37eea16cf533508..d74f4b0215b39ee778bfea8658553b32a25d62d1 100644 (file)
 %                       MagickCore Utility Methods                            %
 %                                                                             %
 %                             Software Design                                 %
-%                               John Cristy                                   %
+%                                  Cristy                                     %
 %                              January 1993                                   %
 %                                                                             %
 %                                                                             %
-%  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  %
@@ -149,7 +149,8 @@ MagickExport MagickBooleanType AcquireUniqueFilename(char *path)
 %
 */
 
-static inline size_t MagickMin(const size_t x,const size_t y)
+static inline MagickSizeType MagickMin(const MagickSizeType x,
+  const MagickSizeType y)
 {
   if (x < y)
     return(x);
@@ -212,7 +213,8 @@ MagickExport MagickBooleanType AcquireUniqueSymbolicLink(const char *source,
     }
   quantum=(size_t) MagickMaxBufferExtent;
   if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0))
-    quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
+    quantum=(size_t) MagickMin((size_t) attributes.st_size,
+      MagickMaxBufferExtent);
   buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
   if (buffer == (unsigned char *) NULL)
     {
@@ -774,6 +776,7 @@ MagickExport MagickBooleanType ExpandFilenames(int *number_arguments,
     *path='\0';
     *filename='\0';
     *subimage='\0';
+    number_files=0;
     vector[count++]=ConstantString(option);
     destroy=MagickTrue;
     parameters=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
@@ -832,7 +835,7 @@ MagickExport MagickBooleanType ExpandFilenames(int *number_arguments,
           Generate file list from file list (e.g. @filelist.txt).
         */
         exception=AcquireExceptionInfo();
-        files=FileToString(option+1,~0,exception);
+        files=FileToString(option+1,~0UL,exception);
         exception=DestroyExceptionInfo(exception);
         if (files == (char *) NULL)
           continue;
@@ -891,7 +894,8 @@ MagickExport MagickBooleanType ExpandFilenames(int *number_arguments,
       if (*path != '\0')
         (void) ConcatenateMagickString(filename,DirectorySeparator,
           MaxTextExtent);
-      (void) ConcatenateMagickString(filename,filelist[j],MaxTextExtent);
+      if (filelist[j] != (char *) NULL)
+        (void) ConcatenateMagickString(filename,filelist[j],MaxTextExtent);
       filelist[j]=DestroyString(filelist[j]);
       if (strlen(filename) >= (MaxTextExtent-1))
         ThrowFatalException(OptionFatalError,"FilenameTruncated");
@@ -1073,6 +1077,14 @@ MagickPrivate MagickBooleanType GetExecutionPath(char *path,const size_t extent)
       program_name=(char *) RelinquishMagickMemory(program_name);
     execution_path=(char *) RelinquishMagickMemory(execution_path);
   }
+#endif
+#if defined(__OpenBSD__)
+  {
+    extern char
+      *__progname;
+
+    (void) CopyMagickString(path,__progname,extent);
+  }
 #endif
   return(IsPathAccessible(path));
 }
@@ -1765,8 +1777,8 @@ MagickExport size_t MultilineCensus(const char *label)
 %
 %  ShredFile() overwrites the specified file with zeros or random data and then
 %  removes it.  The overwrite is optional and is only required to help keep
-%  the contents of the file private.  The first, the file is zeroed.  For
-%  other passes, random data is written.
+%  the contents of the file private.  On the first pass, the file is zeroed.
+%  For subsequent passes, random data is written.
 %
 %  The format of the ShredFile method is:
 %
@@ -1780,10 +1792,7 @@ MagickExport size_t MultilineCensus(const char *label)
 MagickPrivate MagickBooleanType ShredFile(const char *path)
 {
   char
-    *iterations;
-
-  ExceptionInfo
-    *exception;
+    *passes;
 
   int
     file,
@@ -1803,13 +1812,8 @@ MagickPrivate MagickBooleanType ShredFile(const char *path)
 
   if ((path == (const char *) NULL) || (*path == '\0'))
     return(MagickFalse);
-  exception=AcquireExceptionInfo();
-  iterations=(char *) GetImageRegistry(StringRegistryType,"temporary-path",
-    exception);
-  exception=DestroyExceptionInfo(exception);
-  if (iterations == (char *) NULL)
-    iterations=GetEnvironmentValue("MAGICK_SHRED_FILE");
-  if (iterations == (char *) NULL)
+  passes=GetEnvironmentValue("MAGICK_SHRED_PASSES");
+  if (passes == (char *) NULL)
     {
       /*
         Don't shred the file, just remove it.
@@ -1821,7 +1825,13 @@ MagickPrivate MagickBooleanType ShredFile(const char *path)
     }
   file=open_utf8(path,O_WRONLY | O_EXCL | O_BINARY,S_MODE);
   if (file == -1)
-    return(MagickFalse);
+    {
+      /*
+        Don't shred the file, just remove it.
+      */
+      status=remove_utf8(path);
+      return(MagickFalse);
+    }
   /*
     Shred the file.
   */
@@ -1830,12 +1840,12 @@ MagickPrivate MagickBooleanType ShredFile(const char *path)
     quantum=(size_t) MagickMin((MagickSizeType) file_stats.st_size,
       MagickMaxBufferExtent);
   length=(MagickSizeType) file_stats.st_size;
-  for (i=0; i < StringToInteger(iterations); i++)
+  for (i=0; i < (ssize_t) StringToInteger(passes); i++)
   {
     RandomInfo
       *random_info;
 
-    register ssize_t
+    register MagickOffsetType
       j;
 
     ssize_t
@@ -1844,13 +1854,13 @@ MagickPrivate MagickBooleanType ShredFile(const char *path)
     if (lseek(file,0,SEEK_SET) < 0)
       break;
     random_info=AcquireRandomInfo();
-    for (j=0; j < length; j+=count)
+    for (j=0; j < (MagickOffsetType) length; j+=count)
     {
       StringInfo
         *key;
 
       key=GetRandomKey(random_info,quantum);
-      if (j == 0)
+      if (i == 0)
         ResetStringInfo(key);  /* zero on first pass */
       count=write(file,GetStringInfoDatum(key),(size_t)
         MagickMin(quantum,length-j));
@@ -1863,14 +1873,14 @@ MagickPrivate MagickBooleanType ShredFile(const char *path)
         }
     }
     random_info=DestroyRandomInfo(random_info);
-    if (j < length)
+    if (j < (MagickOffsetType) length)
       break;
   }
   status=close(file);
   status=remove_utf8(path);
   if (status == -1)
     return(MagickFalse);
-  return(i < StringToInteger(iterations) ? MagickFalse : MagickTrue);
+  return(i < (ssize_t) StringToInteger(passes) ? MagickFalse : MagickTrue);
 }
 \f
 /*