% 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 %
%
*/
-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);
}
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)
{
*path='\0';
*filename='\0';
*subimage='\0';
+ number_files=0;
vector[count++]=ConstantString(option);
destroy=MagickTrue;
parameters=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
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;
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");
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));
}
%
% 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:
%
MagickPrivate MagickBooleanType ShredFile(const char *path)
{
char
- *iterations;
-
- ExceptionInfo
- *exception;
+ *passes;
int
file,
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.
}
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.
*/
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
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));
}
}
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
/*