2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % U U TTTTT IIIII L IIIII TTTTT Y Y %
10 % UUU T IIIII LLLLL IIIII T Y %
13 % MagickCore Utility Methods %
20 % Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/property.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/color.h"
46 #include "MagickCore/exception.h"
47 #include "MagickCore/exception-private.h"
48 #include "MagickCore/geometry.h"
49 #include "MagickCore/list.h"
50 #include "MagickCore/log.h"
51 #include "MagickCore/magick-private.h"
52 #include "MagickCore/memory_.h"
53 #include "MagickCore/nt-base-private.h"
54 #include "MagickCore/option.h"
55 #include "MagickCore/policy.h"
56 #include "MagickCore/random_.h"
57 #include "MagickCore/registry.h"
58 #include "MagickCore/resource_.h"
59 #include "MagickCore/semaphore.h"
60 #include "MagickCore/signature-private.h"
61 #include "MagickCore/statistic.h"
62 #include "MagickCore/string_.h"
63 #include "MagickCore/string-private.h"
64 #include "MagickCore/token.h"
65 #include "MagickCore/token-private.h"
66 #include "MagickCore/utility.h"
67 #include "MagickCore/utility-private.h"
68 #if defined(MAGICKCORE_HAVE_PROCESS_H)
71 #if defined(MAGICKCORE_HAVE_MACH_O_DYLD_H)
72 #include <mach-o/dyld.h>
79 Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
85 IsPathDirectory(const char *);
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 % A c q u i r e U n i q u e F i l e n a m e %
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 % AcquireUniqueFilename() replaces the contents of path by a unique path name.
100 % The format of the AcquireUniqueFilename method is:
102 % MagickBooleanType AcquireUniqueFilename(char *path)
104 % A description of each parameter follows.
106 % o path: Specifies a pointer to an array of characters. The unique path
107 % name is returned in this array.
110 MagickExport MagickBooleanType AcquireUniqueFilename(char *path)
115 file=AcquireUniqueFileResource(path);
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 % A c q u i r e U n i q u e S ym b o l i c L i n k %
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 % AcquireUniqueSymbolicLink() creates a unique symbolic link to the specified
134 % source path and returns MagickTrue on success otherwise MagickFalse. If the
135 % symlink() method fails or is not available, a unique file name is generated
136 % and the source file copied to it. When you are finished with the file, use
137 % RelinquishUniqueFilename() to destroy it.
139 % The format of the AcquireUniqueSymbolicLink method is:
141 % MagickBooleanType AcquireUniqueSymbolicLink(const char *source,
144 % A description of each parameter follows.
146 % o source: the source path.
148 % o destination: the destination path.
152 static inline MagickSizeType MagickMin(const MagickSizeType x,
153 const MagickSizeType y)
160 MagickExport MagickBooleanType AcquireUniqueSymbolicLink(const char *source,
180 assert(source != (const char *) NULL);
181 assert(destination != (char *) NULL);
182 #if defined(MAGICKCORE_HAVE_SYMLINK)
183 (void) AcquireUniqueFilename(destination);
184 (void) RelinquishUniqueFileResource(destination);
185 if (*source == *DirectorySeparator)
187 if (symlink(source,destination) == 0)
196 if (getcwd(path,MaxTextExtent) == (char *) NULL)
198 (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent);
199 (void) ConcatenateMagickString(path,source,MaxTextExtent);
200 if (symlink(path,destination) == 0)
204 destination_file=AcquireUniqueFileResource(destination);
205 if (destination_file == -1)
207 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
208 if (source_file == -1)
210 (void) close(destination_file);
211 (void) RelinquishUniqueFileResource(destination);
214 quantum=(size_t) MagickMaxBufferExtent;
215 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0))
216 quantum=(size_t) MagickMin((size_t) attributes.st_size,
217 MagickMaxBufferExtent);
218 buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
219 if (buffer == (unsigned char *) NULL)
221 (void) close(source_file);
222 (void) close(destination_file);
223 (void) RelinquishUniqueFileResource(destination);
228 count=(ssize_t) read(source_file,buffer,quantum);
231 length=(size_t) count;
232 count=(ssize_t) write(destination_file,buffer,length);
233 if ((size_t) count != length)
235 (void) close(destination_file);
236 (void) close(source_file);
237 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
238 (void) RelinquishUniqueFileResource(destination);
242 (void) close(destination_file);
243 (void) close(source_file);
244 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 % A p p e n d I m a g e F o r m a t %
257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 % AppendImageFormat() appends the image format type to the filename. If an
260 % extension to the file already exists, it is first removed.
262 % The format of the AppendImageFormat method is:
264 % void AppendImageFormat(const char *format,char *filename)
266 % A description of each parameter follows.
268 % o format: Specifies a pointer to an array of characters. This the
269 % format of the image.
271 % o filename: Specifies a pointer to an array of characters. The unique
272 % file name is returned in this array.
275 MagickExport void AppendImageFormat(const char *format,char *filename)
278 extension[MaxTextExtent],
281 assert(format != (char *) NULL);
282 assert(filename != (char *) NULL);
283 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
284 if ((*format == '\0') || (*filename == '\0'))
286 if (LocaleCompare(filename,"-") == 0)
289 message[MaxTextExtent];
291 (void) FormatLocaleString(message,MaxTextExtent,"%s:%s",format,filename);
292 (void) CopyMagickString(filename,message,MaxTextExtent);
295 GetPathComponent(filename,ExtensionPath,extension);
296 if ((LocaleCompare(extension,"Z") == 0) ||
297 (LocaleCompare(extension,"bz2") == 0) ||
298 (LocaleCompare(extension,"gz") == 0) ||
299 (LocaleCompare(extension,"wmz") == 0) ||
300 (LocaleCompare(extension,"svgz") == 0))
302 GetPathComponent(filename,RootPath,root);
303 (void) CopyMagickString(filename,root,MaxTextExtent);
304 GetPathComponent(filename,RootPath,root);
305 (void) FormatLocaleString(filename,MaxTextExtent,"%s.%s.%s",root,format,
309 GetPathComponent(filename,RootPath,root);
310 (void) FormatLocaleString(filename,MaxTextExtent,"%s.%s",root,format);
314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318 % B a s e 6 4 D e c o d e %
322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
324 % Base64Decode() decodes Base64-encoded text and returns its binary
325 % equivalent. NULL is returned if the text is not valid Base64 data, or a
326 % memory allocation failure occurs.
328 % The format of the Base64Decode method is:
330 % unsigned char *Base64Decode(const char *source,length_t *length)
332 % A description of each parameter follows:
334 % o source: A pointer to a Base64-encoded string.
336 % o length: the number of bytes decoded.
339 MagickExport unsigned char *Base64Decode(const char *source,size_t *length)
354 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
355 assert(source != (char *) NULL);
356 assert(length != (size_t *) NULL);
358 decode=(unsigned char *) AcquireQuantumMemory(strlen(source)/4+4,
360 if (decode == (unsigned char *) NULL)
361 return((unsigned char *) NULL);
364 for (p=source; *p != '\0'; p++)
366 if (isspace((int) ((unsigned char) *p)) != 0)
371 if (q == (char *) NULL)
373 decode=(unsigned char *) RelinquishMagickMemory(decode);
374 return((unsigned char *) NULL); /* non-Base64 character */
380 decode[i]=(q-Base64) << 2;
386 decode[i++]|=(q-Base64) >> 4;
387 decode[i]=((q-Base64) & 0x0f) << 4;
393 decode[i++]|=(q-Base64) >> 2;
394 decode[i]=((q-Base64) & 0x03) << 6;
400 decode[i++]|=(q-Base64);
407 Verify Base-64 string has proper terminal characters.
413 decode=(unsigned char *) RelinquishMagickMemory(decode);
414 return((unsigned char *) NULL);
426 Unrecognized '=' character.
428 decode=(unsigned char *) RelinquishMagickMemory(decode);
429 return((unsigned char *) NULL);
433 for ( ; *p != '\0'; p++)
434 if (isspace((int) ((unsigned char) *p)) == 0)
438 decode=(unsigned char *) RelinquishMagickMemory(decode);
439 return((unsigned char *) NULL);
445 for ( ; *p != '\0'; p++)
446 if (isspace((int) ((unsigned char) *p)) == 0)
448 decode=(unsigned char *) RelinquishMagickMemory(decode);
449 return((unsigned char *) NULL);
451 if ((int) decode[i] != 0)
453 decode=(unsigned char *) RelinquishMagickMemory(decode);
454 return((unsigned char *) NULL);
464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
468 % B a s e 6 4 E n c o d e %
472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
474 % Base64Encode() encodes arbitrary binary data to Base64 encoded format as
475 % described by the "Base64 Content-Transfer-Encoding" section of RFC 2045 and
476 % returns the result as a null-terminated ASCII string. NULL is returned if
477 % a memory allocation failure occurs.
479 % The format of the Base64Encode method is:
481 % char *Base64Encode(const unsigned char *blob,const size_t blob_length,
482 % size_t *encode_length)
484 % A description of each parameter follows:
486 % o blob: A pointer to binary data to encode.
488 % o blob_length: the number of bytes to encode.
490 % o encode_length: The number of bytes encoded.
493 MagickExport char *Base64Encode(const unsigned char *blob,
494 const size_t blob_length,size_t *encode_length)
499 register const unsigned char
508 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
509 assert(blob != (const unsigned char *) NULL);
510 assert(blob_length != 0);
511 assert(encode_length != (size_t *) NULL);
513 encode=(char *) AcquireQuantumMemory(blob_length/3+4,4*sizeof(*encode));
514 if (encode == (char *) NULL)
515 return((char *) NULL);
517 for (p=blob; p < (blob+blob_length-2); p+=3)
519 encode[i++]=Base64[(int) (*p >> 2)];
520 encode[i++]=Base64[(int) (((*p & 0x03) << 4)+(*(p+1) >> 4))];
521 encode[i++]=Base64[(int) (((*(p+1) & 0x0f) << 2)+(*(p+2) >> 6))];
522 encode[i++]=Base64[(int) (*(p+2) & 0x3f)];
524 remainder=blob_length % 3;
536 for (j=0; j < (ssize_t) remainder; j++)
538 encode[i++]=Base64[(int) (code[0] >> 2)];
539 encode[i++]=Base64[(int) (((code[0] & 0x03) << 4)+(code[1] >> 4))];
543 encode[i++]=Base64[(int) (((code[1] & 0x0f) << 2)+(code[2] >> 6))];
552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
556 % C h o p P a t h C o m p o n e n t s %
560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
562 % ChopPathComponents() removes the number of specified file components from a
565 % The format of the ChopPathComponents method is:
567 % ChopPathComponents(char *path,size_t components)
569 % A description of each parameter follows:
573 % o components: The number of components to chop.
576 MagickPrivate void ChopPathComponents(char *path,const size_t components)
581 for (i=0; i < (ssize_t) components; i++)
582 GetPathComponent(path,HeadPath,path);
586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
590 % E x p a n d F i l e n a m e %
594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
596 % ExpandFilename() expands '~' in a path.
598 % The format of the ExpandFilename function is:
600 % ExpandFilename(char *path)
602 % A description of each parameter follows:
604 % o path: Specifies a pointer to a character array that contains the
608 MagickPrivate void ExpandFilename(char *path)
611 expand_path[MaxTextExtent];
613 if (path == (char *) NULL)
617 (void) CopyMagickString(expand_path,path,MaxTextExtent);
618 if ((*(path+1) == *DirectorySeparator) || (*(path+1) == '\0'))
624 Substitute ~ with $HOME.
626 (void) CopyMagickString(expand_path,".",MaxTextExtent);
627 (void) ConcatenateMagickString(expand_path,path+1,MaxTextExtent);
628 home=GetEnvironmentValue("HOME");
629 if (home == (char *) NULL)
630 home=GetEnvironmentValue("USERPROFILE");
631 if (home != (char *) NULL)
633 (void) CopyMagickString(expand_path,home,MaxTextExtent);
634 (void) ConcatenateMagickString(expand_path,path+1,MaxTextExtent);
635 home=DestroyString(home);
640 #if defined(MAGICKCORE_POSIX_SUPPORT) && !defined(__OS2__)
642 username[MaxTextExtent];
651 Substitute ~ with home directory from password file.
653 (void) CopyMagickString(username,path+1,MaxTextExtent);
654 p=strchr(username,'/');
655 if (p != (char *) NULL)
657 entry=getpwnam(username);
658 if (entry == (struct passwd *) NULL)
660 (void) CopyMagickString(expand_path,entry->pw_dir,MaxTextExtent);
661 if (p != (char *) NULL)
663 (void) ConcatenateMagickString(expand_path,"/",MaxTextExtent);
664 (void) ConcatenateMagickString(expand_path,p+1,MaxTextExtent);
668 (void) CopyMagickString(path,expand_path,MaxTextExtent);
672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
676 % E x p a n d F i l e n a m e s %
680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
682 % ExpandFilenames() checks each argument of the given argument array, and
683 % expands it if they have a wildcard character.
685 % Any coder prefix (EG: 'coder:filename') or read modifier postfix (EG:
686 % 'filename[...]') are ignored during the file the expansion, but will be
687 % included in the final argument. If no filename matching the meta-character
688 % 'glob' is found the original argument is returned.
690 % For example, an argument of '*.gif[20x20]' will be replaced by the list
691 % 'abc.gif[20x20]', 'foobar.gif[20x20]', 'xyzzy.gif[20x20]'
692 % if such filenames exist, (in the current directory in this case).
694 % Meta-characters handled...
695 % @ read a list of filenames (no further expansion performed)
696 % ~ At start of filename expands to HOME environemtn variable
697 % * matches any string including an empty string
698 % ? matches by any single character
700 % WARNING: filenames starting with '.' (hidden files in a UNIX file system)
701 % will never be expanded. Attempting to epand '.*' will produce no change.
703 % Expansion is ignored for coders "label:" "caption:" "pango:" and "vid:".
704 % Which provide their own '@' meta-character handling.
706 % You can see the results of the expansion using "Configure" log events.
708 % The returned list should be freed using DestroyStringList().
710 % However the strings in the original pointed to argv are not
711 % freed (TO BE CHECKED). So a copy of the original pointer (and count)
712 % should be kept separate if they need to be freed later.
714 % The format of the ExpandFilenames function is:
716 % status=ExpandFilenames(int *number_arguments,char ***arguments)
718 % A description of each parameter follows:
720 % o number_arguments: Specifies a pointer to an integer describing the
721 % number of elements in the argument vector.
723 % o arguments: Specifies a pointer to a text array containing the command
727 MagickExport MagickBooleanType ExpandFilenames(int *number_arguments,
732 home_directory[MaxTextExtent],
747 Allocate argument vector.
749 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
750 assert(number_arguments != (int *) NULL);
751 assert(arguments != (char ***) NULL);
752 vector=(char **) AcquireQuantumMemory((size_t) (*number_arguments+1),
754 if (vector == (char **) NULL)
755 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
757 Expand any wildcard filenames.
759 *home_directory='\0';
761 for (i=0; i < (ssize_t) *number_arguments; i++)
765 filename[MaxTextExtent],
766 magick[MaxTextExtent],
769 subimage[MaxTextExtent];
774 option=(*arguments)[i];
780 vector[count++]=ConstantString(option);
782 parameters=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
786 Do not expand command option parameters.
788 for (j=0; j < parameters; j++)
791 if (i == (ssize_t) *number_arguments)
793 option=(*arguments)[i];
794 vector[count++]=ConstantString(option);
798 if ((*option == '"') || (*option == '\''))
800 GetPathComponent(option,TailPath,filename);
801 GetPathComponent(option,MagickPath,magick);
802 if ((LocaleCompare(magick,"CAPTION") == 0) ||
803 (LocaleCompare(magick,"LABEL") == 0) ||
804 (LocaleCompare(magick,"PANGO") == 0) ||
805 (LocaleCompare(magick,"VID") == 0))
807 if ((IsGlob(filename) == MagickFalse) && (*option != '@'))
812 Generate file list from wildcard filename (e.g. *.jpg).
814 GetPathComponent(option,HeadPath,path);
815 GetPathComponent(option,SubimagePath,subimage);
816 ExpandFilename(path);
817 if (*home_directory == '\0')
818 directory=getcwd(home_directory,MaxTextExtent-1);
820 filelist=ListFiles(*path == '\0' ? home_directory : path,filename,
835 Generate file list from file list (e.g. @filelist.txt).
837 exception=AcquireExceptionInfo();
838 files=FileToString(option+1,~0UL,exception);
839 exception=DestroyExceptionInfo(exception);
840 if (files == (char *) NULL)
842 filelist=StringToArgv(files,&length);
843 if (filelist == (char **) NULL)
845 files=DestroyString(files);
846 filelist[0]=DestroyString(filelist[0]);
847 for (j=0; j < (ssize_t) (length-1); j++)
848 filelist[j]=filelist[j+1];
849 number_files=(size_t) length-1;
851 if (filelist == (char **) NULL)
853 for (j=0; j < (ssize_t) number_files; j++)
854 if (IsPathDirectory(filelist[j]) <= 0)
856 if (j == (ssize_t) number_files)
858 for (j=0; j < (ssize_t) number_files; j++)
859 filelist[j]=DestroyString(filelist[j]);
860 filelist=(char **) RelinquishMagickMemory(filelist);
864 Transfer file list to argument vector.
866 vector=(char **) ResizeQuantumMemory(vector,(size_t) *number_arguments+
867 count+number_files+1,sizeof(*vector));
868 if (vector == (char **) NULL)
870 for (j=0; j < (ssize_t) number_files; j++)
873 parameters=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
880 Do not expand command option parameters.
882 vector[count++]=ConstantString(option);
883 for (k=0; k < parameters; k++)
886 if (j == (ssize_t) number_files)
889 vector[count++]=ConstantString(option);
893 (void) CopyMagickString(filename,path,MaxTextExtent);
895 (void) ConcatenateMagickString(filename,DirectorySeparator,
897 if (filelist[j] != (char *) NULL)
898 (void) ConcatenateMagickString(filename,filelist[j],MaxTextExtent);
899 filelist[j]=DestroyString(filelist[j]);
900 if (strlen(filename) >= (MaxTextExtent-1))
901 ThrowFatalException(OptionFatalError,"FilenameTruncated");
902 if (IsPathDirectory(filename) <= 0)
910 (void) ConcatenateMagickString(path,magick,MaxTextExtent);
911 (void) ConcatenateMagickString(path,":",MaxTextExtent);
913 (void) ConcatenateMagickString(path,filename,MaxTextExtent);
914 if (*subimage != '\0')
916 (void) ConcatenateMagickString(path,"[",MaxTextExtent);
917 (void) ConcatenateMagickString(path,subimage,MaxTextExtent);
918 (void) ConcatenateMagickString(path,"]",MaxTextExtent);
920 if (strlen(path) >= (MaxTextExtent-1))
921 ThrowFatalException(OptionFatalError,"FilenameTruncated");
922 if (destroy != MagickFalse)
925 vector[count]=DestroyString(vector[count]);
928 vector[count++]=ConstantString(path);
931 filelist=(char **) RelinquishMagickMemory(filelist);
933 vector[count]=(char *) NULL;
934 if (IsEventLogging() != MagickFalse)
939 command_line=AcquireString(vector[0]);
940 for (i=1; i < count; i++)
942 (void) ConcatenateString(&command_line," {");
943 (void) ConcatenateString(&command_line,vector[i]);
944 (void) ConcatenateString(&command_line,"}");
946 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
947 "Command line: %s",command_line);
948 command_line=DestroyString(command_line);
950 *number_arguments=(int) count;
956 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
960 % G e t E x e c u t i o n P a t h %
964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
966 % GetExecutionPath() returns the pathname of the executable that started
967 % the process. On success MagickTrue is returned, otherwise MagickFalse.
969 % The format of the GetExecutionPath method is:
971 % MagickBooleanType GetExecutionPath(char *path,const size_t extent)
973 % A description of each parameter follows:
975 % o path: the pathname of the executable that started the process.
977 % o extent: the maximum extent of the path.
980 MagickPrivate MagickBooleanType GetExecutionPath(char *path,const size_t extent)
986 directory=getcwd(path,(unsigned long) extent);
988 #if defined(MAGICKCORE_HAVE_GETPID) && defined(MAGICKCORE_HAVE_READLINK) && defined(PATH_MAX)
991 link_path[MaxTextExtent],
992 execution_path[PATH_MAX+1];
997 (void) FormatLocaleString(link_path,MaxTextExtent,"/proc/%.20g/exe",
999 count=readlink(link_path,execution_path,PATH_MAX);
1002 (void) FormatLocaleString(link_path,MaxTextExtent,"/proc/%.20g/file",
1004 count=readlink(link_path,execution_path,PATH_MAX);
1006 if ((count > 0) && (count <= (ssize_t) PATH_MAX))
1008 execution_path[count]='\0';
1009 (void) CopyMagickString(path,execution_path,extent);
1013 #if defined(MAGICKCORE_HAVE__NSGETEXECUTABLEPATH)
1016 executable_path[PATH_MAX << 1],
1017 execution_path[PATH_MAX+1];
1022 length=sizeof(executable_path);
1023 if ((_NSGetExecutablePath(executable_path,&length) == 0) &&
1024 (realpath(executable_path,execution_path) != (char *) NULL))
1025 (void) CopyMagickString(path,execution_path,extent);
1028 #if defined(MAGICKCORE_HAVE_GETEXECNAME)
1033 execution_path=(const char *) getexecname();
1034 if (execution_path != (const char *) NULL)
1036 if (*execution_path != *DirectorySeparator)
1037 (void) ConcatenateMagickString(path,DirectorySeparator,extent);
1038 (void) ConcatenateMagickString(path,execution_path,extent);
1042 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1043 NTGetExecutionPath(path,extent);
1045 #if defined(__GNU__)
1055 execution_path=(char *) NULL;
1056 program_name=program_invocation_name;
1057 if (*program_invocation_name != '/')
1062 extent=strlen(directory)+strlen(program_name)+2;
1063 program_name=AcquireQuantumMemory(extent,sizeof(*program_name));
1064 if (program_name == (char *) NULL)
1065 program_name=program_invocation_name;
1067 count=FormatLocaleString(program_name,extent,"%s/%s",directory,
1068 program_invocation_name);
1072 execution_path=realpath(program_name,NULL);
1073 if (execution_path != (char *) NULL)
1074 (void) CopyMagickString(path,execution_path,extent);
1076 if (program_name != program_invocation_name)
1077 program_name=(char *) RelinquishMagickMemory(program_name);
1078 execution_path=(char *) RelinquishMagickMemory(execution_path);
1081 #if defined(__OpenBSD__)
1086 (void) CopyMagickString(path,__progname,extent);
1089 return(IsPathAccessible(path));
1093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1097 % G e t M a g i c k P a g e S i z e %
1101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1103 % GetMagickPageSize() returns the memory page size.
1105 % The format of the GetMagickPageSize method is:
1107 % ssize_t GetMagickPageSize()
1110 MagickPrivate ssize_t GetMagickPageSize(void)
1117 #if defined(MAGICKCORE_HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
1118 page_size=(ssize_t) sysconf(_SC_PAGE_SIZE);
1120 #if defined(MAGICKCORE_HAVE_GETPAGESIZE)
1121 page_size=(ssize_t) getpagesize();
1130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1134 % G e t P a t h A t t r i b u t e s %
1138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1140 % GetPathAttributes() returns attributes (e.g. size of file) about a path.
1142 % The path of the GetPathAttributes method is:
1144 % MagickBooleanType GetPathAttributes(const char *path,void *attributes)
1146 % A description of each parameter follows.
1148 % o path: the file path.
1150 % o attributes: the path attributes are returned here.
1153 MagickExport MagickBooleanType GetPathAttributes(const char *path,
1159 if (path == (const char *) NULL)
1162 return(MagickFalse);
1164 status=stat_utf8(path,(struct stat *) attributes) == 0 ? MagickTrue :
1170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1174 % G e t P a t h C o m p o n e n t %
1178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1180 % GetPathComponent() returns the parent directory name, filename, basename, or
1181 % extension of a file path.
1183 % The component string pointed to must have at least MaxTextExtent space
1184 % for the results to be stored.
1186 % The format of the GetPathComponent function is:
1188 % GetPathComponent(const char *path,PathType type,char *component)
1190 % A description of each parameter follows:
1192 % o path: Specifies a pointer to a character array that contains the
1195 % o type: Specififies which file path component to return.
1197 % o component: the selected file path component is returned here.
1200 MagickExport void GetPathComponent(const char *path,PathType type,
1204 magick[MaxTextExtent],
1206 subimage[MaxTextExtent];
1211 assert(path != (const char *) NULL);
1212 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",path);
1213 assert(component != (char *) NULL);
1219 (void) CopyMagickString(component,path,MaxTextExtent);
1221 #if defined(__OS2__)
1224 for (p=component; *p != '\0'; p++)
1226 if ((*p == '%') && (*(p+1) == '['))
1231 for (p++; (*p != ']') && (*p != '\0'); p++) ;
1235 if ((*p == ':') && (IsPathDirectory(path) < 0) &&
1236 (IsPathAccessible(path) == MagickFalse))
1239 Look for image format specification (e.g. ps3:image).
1241 (void) CopyMagickString(magick,component,(size_t) (p-component+1));
1242 if (IsMagickConflict(magick) != MagickFalse)
1245 for (q=component; *q != '\0'; q++)
1253 p=component+strlen(component)-1;
1254 if ((*p == ']') && (strchr(component,'[') != (char *) NULL) &&
1255 (IsPathAccessible(path) == MagickFalse))
1258 Look for scene specification (e.g. img0001.pcd[4]).
1260 for (q=p-1; q > component; q--)
1265 (void) CopyMagickString(subimage,q+1,MaxTextExtent);
1266 subimage[p-q-1]='\0';
1267 if ((IsSceneGeometry(subimage,MagickFalse) == MagickFalse) &&
1268 (IsGeometry(subimage) == MagickFalse))
1276 for (p=component+strlen(component)-1; p > component; p--)
1277 if (IsBasenameSeparator(*p) != MagickFalse)
1283 (void) CopyMagickString(component,magick,MaxTextExtent);
1288 for (p=component+(strlen(component)-1); p > component; p--)
1290 if (IsBasenameSeparator(*p) != MagickFalse)
1306 if (IsBasenameSeparator(*p) != MagickFalse)
1307 (void) CopyMagickMemory((unsigned char *) component,
1308 (const unsigned char *) (p+1),strlen(p+1)+1);
1313 if (IsBasenameSeparator(*p) != MagickFalse)
1314 (void) CopyMagickString(component,p+1,MaxTextExtent);
1315 for (p=component+(strlen(component)-1); p > component; p--)
1325 if (IsBasenameSeparator(*p) != MagickFalse)
1326 (void) CopyMagickString(component,p+1,MaxTextExtent);
1329 for (p=component+strlen(component)-1; p > component; p--)
1334 (void) CopyMagickString(component,p+1,MaxTextExtent);
1339 (void) CopyMagickString(component,subimage,MaxTextExtent);
1349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1353 % G e t P a t h C o m p o n e n t s %
1357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1359 % GetPathComponents() returns a list of path components.
1361 % The format of the GetPathComponents method is:
1363 % char **GetPathComponents(const char *path,
1364 % size_t *number_componenets)
1366 % A description of each parameter follows:
1368 % o path: Specifies the string to segment into a list.
1370 % o number_components: return the number of components in the list
1373 MagickPrivate char **GetPathComponents(const char *path,
1374 size_t *number_components)
1386 if (path == (char *) NULL)
1387 return((char **) NULL);
1388 *number_components=1;
1389 for (p=path; *p != '\0'; p++)
1390 if (IsBasenameSeparator(*p))
1391 (*number_components)++;
1392 components=(char **) AcquireQuantumMemory((size_t) *number_components+1UL,
1393 sizeof(*components));
1394 if (components == (char **) NULL)
1395 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1397 for (i=0; i < (ssize_t) *number_components; i++)
1399 for (q=p; *q != '\0'; q++)
1400 if (IsBasenameSeparator(*q))
1402 components[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+MaxTextExtent,
1403 sizeof(**components));
1404 if (components[i] == (char *) NULL)
1405 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1406 (void) CopyMagickString(components[i],p,(size_t) (q-p+1));
1409 components[i]=(char *) NULL;
1414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1418 % I s P a t h A c c e s s i b l e %
1422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1424 % IsPathAccessible() returns MagickTrue if the file as defined by the path is
1427 % The format of the IsPathAccessible method is:
1429 % MagickBooleanType IsPathAccessible(const char *path)
1431 % A description of each parameter follows.
1433 % o path: Specifies a path to a file.
1436 MagickExport MagickBooleanType IsPathAccessible(const char *path)
1444 if ((path == (const char *) NULL) || (*path == '\0'))
1445 return(MagickFalse);
1446 status=GetPathAttributes(path,&attributes);
1447 if (status == MagickFalse)
1449 if (S_ISREG(attributes.st_mode) == 0)
1450 return(MagickFalse);
1451 if (access_utf8(path,F_OK) != 0)
1452 return(MagickFalse);
1457 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1461 + I s P a t h D i r e c t o r y %
1465 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1467 % IsPathDirectory() returns -1 if the directory does not exist, 1 is returned
1468 % if the path represents a directory otherwise 0.
1470 % The format of the IsPathDirectory method is:
1472 % int IsPathDirectory(const char *path)
1474 % A description of each parameter follows.
1476 % o path: The directory path.
1479 static int IsPathDirectory(const char *path)
1487 if ((path == (const char *) NULL) || (*path == '\0'))
1488 return(MagickFalse);
1489 status=GetPathAttributes(path,&attributes);
1490 if (status == MagickFalse)
1492 if (S_ISDIR(attributes.st_mode) == 0)
1498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1502 % L i s t F i l e s %
1506 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1508 % ListFiles() reads the directory specified and returns a list of filenames
1509 % contained in the directory sorted in ascending alphabetic order.
1511 % The format of the ListFiles function is:
1513 % char **ListFiles(const char *directory,const char *pattern,
1514 % ssize_t *number_entries)
1516 % A description of each parameter follows:
1518 % o filelist: Method ListFiles returns a list of filenames contained
1519 % in the directory. If the directory specified cannot be read or it is
1520 % a file a NULL list is returned.
1522 % o directory: Specifies a pointer to a text string containing a directory
1525 % o pattern: Specifies a pointer to a text string containing a pattern.
1527 % o number_entries: This integer returns the number of filenames in the
1532 #if defined(__cplusplus) || defined(c_plusplus)
1536 static int FileCompare(const void *x,const void *y)
1542 p=(const char **) x;
1543 q=(const char **) y;
1544 return(LocaleCompare(*p,*q));
1547 #if defined(__cplusplus) || defined(c_plusplus)
1551 static inline int MagickReadDirectory(DIR *directory,struct dirent *entry,
1552 struct dirent **result)
1554 #if defined(MAGICKCORE_HAVE_READDIR_R)
1555 return(readdir_r(directory,entry,result));
1559 *result=readdir(directory);
1564 MagickPrivate char **ListFiles(const char *directory,const char *pattern,
1565 size_t *number_entries)
1583 assert(directory != (const char *) NULL);
1584 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",directory);
1585 assert(pattern != (const char *) NULL);
1586 assert(number_entries != (size_t *) NULL);
1588 current_directory=opendir(directory);
1589 if (current_directory == (DIR *) NULL)
1590 return((char **) NULL);
1595 filelist=(char **) AcquireQuantumMemory((size_t) max_entries,
1597 if (filelist == (char **) NULL)
1599 (void) closedir(current_directory);
1600 return((char **) NULL);
1603 Save the current and change to the new directory.
1605 buffer=(struct dirent *) AcquireMagickMemory(sizeof(*buffer)+
1607 if (buffer == (struct dirent *) NULL)
1608 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1609 while ((MagickReadDirectory(current_directory,buffer,&entry) == 0) &&
1610 (entry != (struct dirent *) NULL))
1612 if (*entry->d_name == '.')
1614 if ((IsPathDirectory(entry->d_name) > 0) ||
1615 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1616 (GlobExpression(entry->d_name,pattern,MagickTrue) != MagickFalse))
1618 (GlobExpression(entry->d_name,pattern,MagickFalse) != MagickFalse))
1621 if (*number_entries >= max_entries)
1624 Extend the file list.
1627 filelist=(char **) ResizeQuantumMemory(filelist,(size_t)
1628 max_entries,sizeof(*filelist));
1629 if (filelist == (char **) NULL)
1637 p=strchr(entry->d_name,';');
1640 if (*number_entries > 0)
1641 if (LocaleCompare(entry->d_name,filelist[*number_entries-1]) == 0)
1645 filelist[*number_entries]=(char *) AcquireString(entry->d_name);
1646 (*number_entries)++;
1649 buffer=(struct dirent *) RelinquishMagickMemory(buffer);
1650 (void) closedir(current_directory);
1651 if (filelist == (char **) NULL)
1652 return((char **) NULL);
1654 Sort filelist in ascending order.
1656 qsort((void *) filelist,(size_t) *number_entries,sizeof(*filelist),
1662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1666 % M a g i c k D e l a y %
1670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1672 % MagickDelay() suspends program execution for the number of milliseconds
1675 % The format of the Delay method is:
1677 % void MagickDelay(const MagickSizeType milliseconds)
1679 % A description of each parameter follows:
1681 % o milliseconds: Specifies the number of milliseconds to delay before
1685 MagickPrivate void MagickDelay(const MagickSizeType milliseconds)
1687 if (milliseconds == 0)
1689 #if defined(MAGICKCORE_HAVE_NANOSLEEP)
1694 timer.tv_sec=(time_t) (milliseconds/1000);
1695 timer.tv_nsec=(milliseconds % 1000)*1000*1000;
1696 (void) nanosleep(&timer,(struct timespec *) NULL);
1698 #elif defined(MAGICKCORE_HAVE_USLEEP)
1699 usleep(1000*milliseconds);
1700 #elif defined(MAGICKCORE_HAVE_SELECT)
1705 timer.tv_sec=(long) milliseconds/1000;
1706 timer.tv_usec=(long) (milliseconds % 1000)*1000;
1707 (void) select(0,(XFD_SET *) NULL,(XFD_SET *) NULL,(XFD_SET *) NULL,&timer);
1709 #elif defined(MAGICKCORE_HAVE_POLL)
1710 (void) poll((struct pollfd *) NULL,0,(int) milliseconds);
1711 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
1712 Sleep((long) milliseconds);
1718 timer=milliseconds/1000.0;
1721 #elif defined(__BEOS__)
1722 snooze(1000*milliseconds);
1724 # error "Time delay method not defined."
1729 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1733 % M u l t i l i n e C e n s u s %
1737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1739 % MultilineCensus() returns the number of lines within a label. A line is
1740 % represented by a \n character.
1742 % The format of the MultilineCenus method is:
1744 % size_t MultilineCensus(const char *label)
1746 % A description of each parameter follows.
1748 % o label: This character string is the label.
1751 MagickExport size_t MultilineCensus(const char *label)
1757 Determine the number of lines within this label.
1759 if (label == (char *) NULL)
1761 for (number_lines=1; *label != '\0'; label++)
1764 return(number_lines);
1768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1772 % S h r e a d F i l e %
1776 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1778 % ShredFile() overwrites the specified file with zeros or random data and then
1779 % removes it. The overwrite is optional and is only required to help keep
1780 % the contents of the file private. On the first pass, the file is zeroed.
1781 % For subsequent passes, random data is written.
1783 % The format of the ShredFile method is:
1785 % MagickBooleanType ShredFile(const char *path)
1787 % A description of each parameter follows.
1789 % o path: Specifies a path to a file.
1792 MagickPrivate MagickBooleanType ShredFile(const char *path)
1816 if ((path == (const char *) NULL) || (*path == '\0'))
1817 return(MagickFalse);
1818 exception=AcquireExceptionInfo();
1819 passes=(char *) GetImageRegistry(StringRegistryType,"shred-passes",exception);
1820 exception=DestroyExceptionInfo(exception);
1821 if (passes == (char *) NULL)
1822 passes=GetEnvironmentValue("MAGICK_SHRED_PASSES");
1823 if (passes == (char *) NULL)
1826 Don't shred the file, just remove it.
1828 status=remove_utf8(path);
1830 return(MagickFalse);
1833 file=open_utf8(path,O_WRONLY | O_EXCL | O_BINARY,S_MODE);
1837 Don't shred the file, just remove it.
1839 status=remove_utf8(path);
1840 return(MagickFalse);
1845 quantum=(size_t) MagickMaxBufferExtent;
1846 if ((fstat(file,&file_stats) == 0) && (file_stats.st_size != 0))
1847 quantum=(size_t) MagickMin((MagickSizeType) file_stats.st_size,
1848 MagickMaxBufferExtent);
1849 length=(MagickSizeType) file_stats.st_size;
1850 for (i=0; i < (ssize_t) StringToInteger(passes); i++)
1855 register MagickOffsetType
1861 if (lseek(file,0,SEEK_SET) < 0)
1863 random_info=AcquireRandomInfo();
1864 for (j=0; j < (MagickOffsetType) length; j+=count)
1869 key=GetRandomKey(random_info,quantum);
1871 ResetStringInfo(key); /* zero on first pass */
1872 count=write(file,GetStringInfoDatum(key),(size_t)
1873 MagickMin(quantum,length-j));
1874 key=DestroyStringInfo(key);
1882 random_info=DestroyRandomInfo(random_info);
1883 if (j < (MagickOffsetType) length)
1887 status=remove_utf8(path);
1889 return(MagickFalse);
1890 return(i < (ssize_t) StringToInteger(passes) ? MagickFalse : MagickTrue);
1894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1898 % S y s t e m C o m m a n d %
1902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1904 % SystemCommand() executes the specified command and waits until it
1905 % terminates. The returned value is the exit status of the command.
1907 % The format of the SystemCommand method is:
1909 % int SystemCommand(const MagickBooleanType asynchronous,
1910 % const MagickBooleanType verbose,const char *command,
1911 % ExceptionInfo *exception)
1913 % A description of each parameter follows:
1915 % o asynchronous: a value other than 0 executes the parent program
1916 % concurrently with the new child process.
1918 % o verbose: a value other than 0 prints the executed command before it is
1921 % o command: this string is the command to execute.
1923 % o exception: return any errors here.
1926 MagickExport int SystemCommand(const MagickBooleanType asynchronous,
1927 const MagickBooleanType verbose,const char *command,ExceptionInfo *exception)
1947 arguments=StringToArgv(command,&number_arguments);
1948 if (arguments == (char **) NULL)
1950 if (*arguments[1] == '\0')
1952 for (i=0; i < (ssize_t) number_arguments; i++)
1953 arguments[i]=DestroyString(arguments[i]);
1954 arguments=(char **) RelinquishMagickMemory(arguments);
1957 rights=ExecutePolicyRights;
1958 domain=DelegatePolicyDomain;
1959 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
1962 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1963 "NotAuthorized","`%s'",arguments[1]);
1964 for (i=0; i < (ssize_t) number_arguments; i++)
1965 arguments[i]=DestroyString(arguments[i]);
1966 arguments=(char **) RelinquishMagickMemory(arguments);
1969 if (verbose != MagickFalse)
1971 (void) FormatLocaleFile(stderr,"%s\n",command);
1972 (void) fflush(stderr);
1974 shell_command=(char *) command;
1975 if (asynchronous != MagickFalse)
1977 shell_command=AcquireString(command);
1978 (void) ConcatenateMagickString(shell_command,"&",MaxTextExtent);
1980 #if defined(MAGICKCORE_POSIX_SUPPORT)
1981 #if !defined(MAGICKCORE_HAVE_EXECVP)
1982 status=system(shell_command);
1984 if ((asynchronous != MagickFalse) ||
1985 (strpbrk(shell_command,"&;<>|") != (char *) NULL))
1986 status=system(shell_command);
1993 Call application directly rather than from a shell.
1995 child_pid=(pid_t) fork();
1996 if (child_pid == (pid_t) -1)
1997 status=system(command);
2001 status=execvp(arguments[1],arguments+1);
2013 pid=(pid_t) waitpid(child_pid,&child_status,0);
2018 if (WIFEXITED(child_status) != 0)
2019 status=WEXITSTATUS(child_status);
2021 if (WIFSIGNALED(child_status))
2027 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
2028 status=NTSystemCommand(shell_command);
2029 #elif defined(macintosh)
2030 status=MACSystemCommand(shell_command);
2032 status=system(shell_command);
2034 # error No suitable system() method.
2037 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
2038 "'%s' (%d)",command,status);
2039 if (shell_command != command)
2040 shell_command=DestroyString(shell_command);
2041 for (i=0; i < (ssize_t) number_arguments; i++)
2042 arguments[i]=DestroyString(arguments[i]);
2043 arguments=(char **) RelinquishMagickMemory(arguments);