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-2010 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 "magick/studio.h"
43 #include "magick/property.h"
44 #include "magick/blob.h"
45 #include "magick/color.h"
46 #include "magick/exception.h"
47 #include "magick/exception-private.h"
48 #include "magick/geometry.h"
49 #include "magick/list.h"
50 #include "magick/log.h"
51 #include "magick/memory_.h"
52 #include "magick/option.h"
53 #include "magick/policy.h"
54 #include "magick/resource_.h"
55 #include "magick/semaphore.h"
56 #include "magick/signature-private.h"
57 #include "magick/statistic.h"
58 #include "magick/string_.h"
59 #include "magick/token.h"
60 #include "magick/utility.h"
61 #if defined(MAGICKCORE_HAVE_PROCESS_H)
64 #if defined(MAGICKCORE_HAVE_MACH_O_DYLD_H)
65 #include <mach-o/dyld.h>
72 Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
78 IsPathDirectory(const char *);
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % A c q u i r e U n i q u e F i l e n a m e %
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 % AcquireUniqueFilename() replaces the contents of path by a unique path name.
93 % The format of the AcquireUniqueFilename method is:
95 % MagickBooleanType AcquireUniqueFilename(char *path)
97 % A description of each parameter follows.
99 % o path: Specifies a pointer to an array of characters. The unique path
100 % name is returned in this array.
103 MagickExport MagickBooleanType AcquireUniqueFilename(char *path)
108 file=AcquireUniqueFileResource(path);
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 % A c q u i r e U n i q u e S ym b o l i c L i n k %
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 % AcquireUniqueSymbolicLink() creates a unique symbolic link to the specified
127 % source path and returns MagickTrue on success otherwise MagickFalse. If the
128 % symlink() method fails or is not available, a unique file name is generated
129 % and the source file copied to it. When you are finished with the file, use
130 % RelinquishUniqueFilename() to destroy it.
132 % The format of the AcquireUniqueSymbolicLink method is:
134 % MagickBooleanType AcquireUniqueSymbolicLink(const char *source,
137 % A description of each parameter follows.
139 % o source: the source path.
141 % o destination: the destination path.
145 static inline size_t MagickMin(const size_t x,const size_t y)
152 MagickExport MagickBooleanType AcquireUniqueSymbolicLink(const char *source,
172 assert(source != (const char *) NULL);
173 assert(destination != (char *) NULL);
174 #if defined(MAGICKCORE_HAVE_SYMLINK)
175 (void) AcquireUniqueFilename(destination);
176 (void) RelinquishUniqueFileResource(destination);
177 if (*source == *DirectorySeparator)
179 if (symlink(source,destination) == 0)
188 if (getcwd(path,MaxTextExtent) == (char *) NULL)
190 (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent);
191 (void) ConcatenateMagickString(path,source,MaxTextExtent);
192 if (symlink(path,destination) == 0)
196 destination_file=AcquireUniqueFileResource(destination);
197 if (destination_file == -1)
199 source_file=open(source,O_RDONLY | O_BINARY);
200 if (source_file == -1)
202 (void) close(destination_file);
203 (void) RelinquishUniqueFileResource(destination);
206 quantum=(size_t) MagickMaxBufferExtent;
207 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0))
208 quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
209 buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
210 if (buffer == (unsigned char *) NULL)
212 (void) close(source_file);
213 (void) close(destination_file);
214 (void) RelinquishUniqueFileResource(destination);
219 count=(ssize_t) read(source_file,buffer,quantum);
222 length=(size_t) count;
223 count=(ssize_t) write(destination_file,buffer,length);
224 if ((size_t) count != length)
226 (void) close(destination_file);
227 (void) close(source_file);
228 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
229 (void) RelinquishUniqueFileResource(destination);
233 (void) close(destination_file);
234 (void) close(source_file);
235 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 % A p p e n d I m a g e F o r m a t %
248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 % AppendImageFormat() appends the image format type to the filename. If an
251 % extension to the file already exists, it is first removed.
253 % The format of the AppendImageFormat method is:
255 % void AppendImageFormat(const char *format,char *filename)
257 % A description of each parameter follows.
259 % o format: Specifies a pointer to an array of characters. This the
260 % format of the image.
262 % o filename: Specifies a pointer to an array of characters. The unique
263 % file name is returned in this array.
266 MagickExport void AppendImageFormat(const char *format,char *filename)
269 extension[MaxTextExtent],
272 assert(format != (char *) NULL);
273 assert(filename != (char *) NULL);
274 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
275 if ((*format == '\0') || (*filename == '\0'))
277 if (LocaleCompare(filename,"-") == 0)
280 message[MaxTextExtent];
282 (void) FormatMagickString(message,MaxTextExtent,"%s:%s",format,filename);
283 (void) CopyMagickString(filename,message,MaxTextExtent);
286 GetPathComponent(filename,ExtensionPath,extension);
287 if ((LocaleCompare(extension,"Z") == 0) ||
288 (LocaleCompare(extension,"bz2") == 0) ||
289 (LocaleCompare(extension,"gz") == 0) ||
290 (LocaleCompare(extension,"wmz") == 0) ||
291 (LocaleCompare(extension,"svgz") == 0))
293 GetPathComponent(filename,RootPath,root);
294 (void) CopyMagickString(filename,root,MaxTextExtent);
295 GetPathComponent(filename,RootPath,root);
296 (void) FormatMagickString(filename,MaxTextExtent,"%s.%s.%s",root,format,
300 GetPathComponent(filename,RootPath,root);
301 (void) FormatMagickString(filename,MaxTextExtent,"%s.%s",root,format);
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 % B a s e 6 4 D e c o d e %
313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 % Base64Decode() decodes Base64-encoded text and returns its binary
316 % equivalent. NULL is returned if the text is not valid Base64 data, or a
317 % memory allocation failure occurs.
319 % The format of the Base64Decode method is:
321 % unsigned char *Base64Decode(const char *source,length_t *length)
323 % A description of each parameter follows:
325 % o source: A pointer to a Base64-encoded string.
327 % o length: the number of bytes decoded.
330 MagickExport unsigned char *Base64Decode(const char *source,size_t *length)
345 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
346 assert(source != (char *) NULL);
347 assert(length != (size_t *) NULL);
349 decode=(unsigned char *) AcquireQuantumMemory(strlen(source)/4+4,
351 if (decode == (unsigned char *) NULL)
352 return((unsigned char *) NULL);
355 for (p=source; *p != '\0'; p++)
357 if (isspace((int) ((unsigned char) *p)) != 0)
362 if (q == (char *) NULL)
364 decode=(unsigned char *) RelinquishMagickMemory(decode);
365 return((unsigned char *) NULL); /* non-Base64 character */
371 decode[i]=(q-Base64) << 2;
377 decode[i++]|=(q-Base64) >> 4;
378 decode[i]=((q-Base64) & 0x0f) << 4;
384 decode[i++]|=(q-Base64) >> 2;
385 decode[i]=((q-Base64) & 0x03) << 6;
391 decode[i++]|=(q-Base64);
398 Verify Base-64 string has proper terminal characters.
404 decode=(unsigned char *) RelinquishMagickMemory(decode);
405 return((unsigned char *) NULL);
417 Unrecognized '=' character.
419 decode=(unsigned char *) RelinquishMagickMemory(decode);
420 return((unsigned char *) NULL);
424 for ( ; *p != '\0'; p++)
425 if (isspace((int) ((unsigned char) *p)) == 0)
429 decode=(unsigned char *) RelinquishMagickMemory(decode);
430 return((unsigned char *) NULL);
436 for ( ; *p != '\0'; p++)
437 if (isspace((int) ((unsigned char) *p)) == 0)
439 decode=(unsigned char *) RelinquishMagickMemory(decode);
440 return((unsigned char *) NULL);
442 if ((int) decode[i] != 0)
444 decode=(unsigned char *) RelinquishMagickMemory(decode);
445 return((unsigned char *) NULL);
455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
459 % B a s e 6 4 E n c o d e %
463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
465 % Base64Encode() encodes arbitrary binary data to Base64 encoded format as
466 % described by the "Base64 Content-Transfer-Encoding" section of RFC 2045 and
467 % returns the result as a null-terminated ASCII string. NULL is returned if
468 % a memory allocation failure occurs.
470 % The format of the Base64Encode method is:
472 % char *Base64Encode(const unsigned char *blob,const size_t blob_length,
473 % size_t *encode_length)
475 % A description of each parameter follows:
477 % o blob: A pointer to binary data to encode.
479 % o blob_length: the number of bytes to encode.
481 % o encode_length: The number of bytes encoded.
484 MagickExport char *Base64Encode(const unsigned char *blob,
485 const size_t blob_length,size_t *encode_length)
490 register const unsigned char
499 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
500 assert(blob != (const unsigned char *) NULL);
501 assert(blob_length != 0);
502 assert(encode_length != (size_t *) NULL);
504 encode=(char *) AcquireQuantumMemory(blob_length/3+4,4*sizeof(*encode));
505 if (encode == (char *) NULL)
506 return((char *) NULL);
508 for (p=blob; p < (blob+blob_length-2); p+=3)
510 encode[i++]=Base64[(int) (*p >> 2)];
511 encode[i++]=Base64[(int) (((*p & 0x03) << 4)+(*(p+1) >> 4))];
512 encode[i++]=Base64[(int) (((*(p+1) & 0x0f) << 2)+(*(p+2) >> 6))];
513 encode[i++]=Base64[(int) (*(p+2) & 0x3f)];
515 remainder=blob_length % 3;
527 for (j=0; j < (ssize_t) remainder; j++)
529 encode[i++]=Base64[(int) (code[0] >> 2)];
530 encode[i++]=Base64[(int) (((code[0] & 0x03) << 4)+(code[1] >> 4))];
534 encode[i++]=Base64[(int) (((code[1] & 0x0f) << 2)+(code[2] >> 6))];
543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
547 % C h o p P a t h C o m p o n e n t s %
551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553 % ChopPathComponents() removes the number of specified file components from a
556 % The format of the ChopPathComponents method is:
558 % ChopPathComponents(char *path,size_t components)
560 % A description of each parameter follows:
564 % o components: The number of components to chop.
567 MagickExport void ChopPathComponents(char *path,const size_t components)
572 for (i=0; i < (ssize_t) components; i++)
573 GetPathComponent(path,HeadPath,path);
577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581 % E x p a n d F i l e n a m e %
585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
587 % ExpandFilename() expands '~' in a path.
589 % The format of the ExpandFilename function is:
591 % ExpandFilename(char *path)
593 % A description of each parameter follows:
595 % o path: Specifies a pointer to a character array that contains the
599 MagickExport void ExpandFilename(char *path)
602 expand_path[MaxTextExtent];
604 if (path == (char *) NULL)
608 (void) CopyMagickString(expand_path,path,MaxTextExtent);
609 if ((*(path+1) == *DirectorySeparator) || (*(path+1) == '\0'))
615 Substitute ~ with $HOME.
617 (void) CopyMagickString(expand_path,".",MaxTextExtent);
618 (void) ConcatenateMagickString(expand_path,path+1,MaxTextExtent);
619 home=GetEnvironmentValue("HOME");
620 if (home == (char *) NULL)
621 home=GetEnvironmentValue("USERPROFILE");
622 if (home != (char *) NULL)
624 (void) CopyMagickString(expand_path,home,MaxTextExtent);
625 (void) ConcatenateMagickString(expand_path,path+1,MaxTextExtent);
626 home=DestroyString(home);
631 #if defined(MAGICKCORE_POSIX_SUPPORT) && !defined(__OS2__)
633 username[MaxTextExtent];
642 Substitute ~ with home directory from password file.
644 (void) CopyMagickString(username,path+1,MaxTextExtent);
645 p=strchr(username,'/');
646 if (p != (char *) NULL)
648 entry=getpwnam(username);
649 if (entry == (struct passwd *) NULL)
651 (void) CopyMagickString(expand_path,entry->pw_dir,MaxTextExtent);
652 if (p != (char *) NULL)
654 (void) ConcatenateMagickString(expand_path,"/",MaxTextExtent);
655 (void) ConcatenateMagickString(expand_path,p+1,MaxTextExtent);
659 (void) CopyMagickString(path,expand_path,MaxTextExtent);
663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
667 % E x p a n d F i l e n a m e s %
671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
673 % ExpandFilenames() checks each argument of the command line vector and
674 % expands it if they have a wildcard character. For example, *.jpg might
675 % expand to: bird.jpg rose.jpg tiki.jpg.
677 % The format of the ExpandFilenames function is:
679 % status=ExpandFilenames(int *number_arguments,char ***arguments)
681 % A description of each parameter follows:
683 % o number_arguments: Specifies a pointer to an integer describing the
684 % number of elements in the argument vector.
686 % o arguments: Specifies a pointer to a text array containing the command
690 MagickExport MagickBooleanType ExpandFilenames(int *number_arguments,
695 home_directory[MaxTextExtent],
710 Allocate argument vector.
712 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
713 assert(number_arguments != (int *) NULL);
714 assert(arguments != (char ***) NULL);
715 vector=(char **) AcquireQuantumMemory((size_t) (*number_arguments+1),
717 if (vector == (char **) NULL)
718 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
720 Expand any wildcard filenames.
722 *home_directory='\0';
724 for (i=0; i < (ssize_t) *number_arguments; i++)
728 filename[MaxTextExtent],
729 magick[MaxTextExtent],
732 subimage[MaxTextExtent];
737 option=(*arguments)[i];
742 vector[count++]=ConstantString(option);
744 parameters=ParseMagickOption(MagickCommandOptions,MagickFalse,option);
748 Do not expand command option parameters.
750 for (j=0; j < parameters; j++)
753 if (i == (ssize_t) *number_arguments)
755 option=(*arguments)[i];
756 vector[count++]=ConstantString(option);
760 if ((*option == '"') || (*option == '\''))
762 GetPathComponent(option,TailPath,filename);
763 GetPathComponent(option,MagickPath,magick);
764 if ((LocaleCompare(magick,"CAPTION") == 0) ||
765 (LocaleCompare(magick,"LABEL") == 0) ||
766 (LocaleCompare(magick,"VID") == 0))
768 if ((IsGlob(filename) == MagickFalse) && (*filename != '@'))
770 if (*filename != '@')
773 Generate file list from wildcard filename (e.g. *.jpg).
775 GetPathComponent(option,HeadPath,path);
776 GetPathComponent(option,SubimagePath,subimage);
777 ExpandFilename(path);
778 if (*home_directory == '\0')
779 cwd=getcwd(home_directory,MaxTextExtent-1);
780 filelist=ListFiles(*path == '\0' ? home_directory : path,filename,
795 Generate file list from file list (e.g. @filelist.txt).
797 exception=AcquireExceptionInfo();
798 files=FileToString(filename+1,~0,exception);
799 exception=DestroyExceptionInfo(exception);
800 if (files == (char *) NULL)
803 filelist=StringToArgv(files,&number_images);
804 files=DestroyString(files);
805 number_files=(size_t) number_images;
808 if (filelist == (char **) NULL)
810 for (j=0; j < (ssize_t) number_files; j++)
811 if (IsPathDirectory(filelist[j]) <= 0)
813 if (j == (ssize_t) number_files)
815 for (j=0; j < (ssize_t) number_files; j++)
816 filelist[j]=DestroyString(filelist[j]);
817 filelist=(char **) RelinquishMagickMemory(filelist);
821 Transfer file list to argument vector.
823 vector=(char **) ResizeQuantumMemory(vector,(size_t) *number_arguments+
824 count+number_files+1,sizeof(*vector));
825 if (vector == (char **) NULL)
827 for (j=0; j < (ssize_t) number_files; j++)
830 parameters=ParseMagickOption(MagickCommandOptions,MagickFalse,option);
837 Do not expand command option parameters.
839 vector[count++]=ConstantString(option);
840 for (k=0; k < parameters; k++)
843 if (j == (ssize_t) number_files)
846 vector[count++]=ConstantString(option);
850 (void) CopyMagickString(filename,path,MaxTextExtent);
852 (void) ConcatenateMagickString(filename,DirectorySeparator,
854 (void) ConcatenateMagickString(filename,filelist[j],MaxTextExtent);
855 filelist[j]=DestroyString(filelist[j]);
856 if (strlen(filename) >= (MaxTextExtent-1))
857 ThrowFatalException(OptionFatalError,"FilenameTruncated");
858 if (IsPathDirectory(filename) <= 0)
866 (void) ConcatenateMagickString(path,magick,MaxTextExtent);
867 (void) ConcatenateMagickString(path,":",MaxTextExtent);
869 (void) ConcatenateMagickString(path,filename,MaxTextExtent);
870 if (*subimage != '\0')
872 (void) ConcatenateMagickString(path,"[",MaxTextExtent);
873 (void) ConcatenateMagickString(path,subimage,MaxTextExtent);
874 (void) ConcatenateMagickString(path,"]",MaxTextExtent);
876 if (strlen(path) >= MaxTextExtent)
877 ThrowFatalException(OptionFatalError,"FilenameTruncated");
878 if (destroy != MagickFalse)
881 vector[count]=DestroyString(vector[count]);
884 vector[count++]=ConstantString(path);
887 filelist=(char **) RelinquishMagickMemory(filelist);
889 vector[count]=(char *) NULL;
890 if (IsEventLogging() != MagickFalse)
895 command_line=AcquireString(vector[0]);
896 for (i=1; i < count; i++)
898 (void) ConcatenateString(&command_line," {");
899 (void) ConcatenateString(&command_line,vector[i]);
900 (void) ConcatenateString(&command_line,"}");
902 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
903 "Command line: %s",command_line);
904 command_line=DestroyString(command_line);
906 *number_arguments=(int) count;
912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
916 % G e t E x e c u t i o n P a t h %
920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
922 % GetExecutionPath() returns the pathname of the executable that started
923 % the process. On success MagickTrue is returned, otherwise MagickFalse.
925 % The format of the GetExecutionPath method is:
927 % MagickBooleanType GetExecutionPath(char *path,const size_t extent)
929 % A description of each parameter follows:
931 % o path: the pathname of the executable that started the process.
933 % o extent: the maximum extent of the path.
936 MagickExport MagickBooleanType GetExecutionPath(char *path,const size_t extent)
942 cwd=getcwd(path,(unsigned long) extent);
943 #if defined(MAGICKCORE_HAVE_GETPID) && defined(MAGICKCORE_HAVE_READLINK) && defined(PATH_MAX)
946 link_path[MaxTextExtent],
947 execution_path[PATH_MAX+1];
952 (void) FormatMagickString(link_path,MaxTextExtent,"/proc/%.20g/exe",
954 count=readlink(link_path,execution_path,PATH_MAX);
957 (void) FormatMagickString(link_path,MaxTextExtent,"/proc/%.20g/file",
959 count=readlink(link_path,execution_path,PATH_MAX);
961 if ((count > 0) && (count <= (ssize_t) PATH_MAX))
963 execution_path[count]='\0';
964 (void) CopyMagickString(path,execution_path,extent);
968 #if defined(MAGICKCORE_HAVE__NSGETEXECUTABLEPATH)
971 executable_path[PATH_MAX << 1],
972 execution_path[PATH_MAX+1];
977 length=sizeof(executable_path);
978 if ((_NSGetExecutablePath(executable_path,&length) == 0) &&
979 (realpath(executable_path,execution_path) != (char *) NULL))
980 (void) CopyMagickString(path,execution_path,extent);
983 #if defined(MAGICKCORE_HAVE_GETEXECNAME)
988 execution_path=(const char *) getexecname();
989 if (execution_path != (const char *) NULL)
991 if (*execution_path != *DirectorySeparator)
992 (void) ConcatenateMagickString(path,DirectorySeparator,extent);
993 (void) ConcatenateMagickString(path,execution_path,extent);
997 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
998 NTGetExecutionPath(path,extent);
1000 #if defined(__GNU__)
1010 execution_path=(char *) NULL;
1011 program_name=program_invocation_name;
1012 if (*program_invocation_name != '/')
1017 extent=strlen(cwd)+strlen(program_name)+1;
1018 program_name=AcquireQuantumMemory(extent,sizeof(*program_name));
1019 if (program_name == (char *) NULL)
1020 program_name=program_invocation_name;
1022 count=FormatMagickString(program_name,extent,"%s/%s",cwd,
1023 program_invocation_name);
1027 execution_path=realpath(program_name,NULL);
1028 if (execution_path != (char *) NULL)
1029 (void) CopyMagickString(path,execution_path,extent);
1031 if (program_name != program_invocation_name)
1032 program_name=(char *) RelinquishMagickMemory(program_name);
1033 execution_path=(char *) RelinquishMagickMemory(execution_path);
1036 return(IsPathAccessible(path));
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1044 % G e t M a g i c k P a g e S i z e %
1048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1050 % GetMagickPageSize() returns the memory page size.
1052 % The format of the GetMagickPageSize method is:
1054 % ssize_t GetMagickPageSize()
1057 MagickExport ssize_t GetMagickPageSize(void)
1064 #if defined(MAGICKCORE_HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
1065 page_size=(ssize_t) sysconf(_SC_PAGE_SIZE);
1067 #if defined(MAGICKCORE_HAVE_GETPAGESIZE)
1068 page_size=(ssize_t) getpagesize();
1077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1081 % G e t P a t h A t t r i b u t e s %
1085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 % GetPathAttributes() returns attributes (e.g. size of file) about a path.
1089 % The path of the GetPathAttributes method is:
1091 % MagickBooleanType GetPathAttributes(const char *path,void *attributes)
1093 % A description of each parameter follows.
1095 % o path: the file path.
1097 % o attributes: the path attributes are returned here.
1101 #if defined(MAGICKCORE_HAVE__WFOPEN)
1102 static size_t UTF8ToUTF16(const unsigned char *utf8,wchar_t *utf16)
1104 register const unsigned char
1107 if (utf16 != (wchar_t *) NULL)
1116 Convert UTF-8 to UTF-16.
1119 for (p=utf8; *p != '\0'; p++)
1121 if ((*p & 0x80) == 0)
1124 if ((*p & 0xE0) == 0xC0)
1129 if ((*p & 0xC0) != 0x80)
1134 if ((*p & 0xF0) == 0xE0)
1139 if ((*p & 0xC0) != 0x80)
1142 *q|=(c & 0x3F) << 6;
1144 if ((*p & 0xC0) != 0x80)
1156 Compute UTF-16 string length.
1158 for (p=utf8; *p != '\0'; p++)
1160 if ((*p & 0x80) == 0)
1163 if ((*p & 0xE0) == 0xC0)
1166 if ((*p & 0xC0) != 0x80)
1170 if ((*p & 0xF0) == 0xE0)
1173 if ((*p & 0xC0) != 0x80)
1176 if ((*p & 0xC0) != 0x80)
1185 static wchar_t *ConvertUTF8ToUTF16(const unsigned char *source)
1193 length=UTF8ToUTF16(source,(wchar_t *) NULL);
1200 Not UTF-8, just copy.
1202 length=strlen((const char *) source);
1203 utf16=(wchar_t *) AcquireQuantumMemory(length+1,sizeof(*utf16));
1204 if (utf16 == (wchar_t *) NULL)
1205 return((wchar_t *) NULL);
1206 for (i=0; i <= (ssize_t) length; i++)
1210 utf16=(wchar_t *) AcquireQuantumMemory(length+1,sizeof(*utf16));
1211 if (utf16 == (wchar_t *) NULL)
1212 return((wchar_t *) NULL);
1213 length=UTF8ToUTF16(source,utf16);
1218 MagickExport MagickBooleanType GetPathAttributes(const char *path,
1224 if (path == (const char *) NULL)
1227 return(MagickFalse);
1229 #if !defined(MAGICKCORE_HAVE__WSTAT)
1230 status=stat(path,(struct stat *) attributes) == 0 ? MagickTrue : MagickFalse;
1236 unicode_path=ConvertUTF8ToUTF16((const unsigned char *) path);
1237 if (unicode_path == (wchar_t *) NULL)
1238 return(MagickFalse);
1239 status=wstat(unicode_path,(struct stat *) attributes) == 0 ? MagickTrue :
1241 unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path);
1248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1252 % G e t P a t h C o m p o n e n t %
1256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1258 % GetPathComponent() returns the parent directory name, filename, basename, or
1259 % extension of a file path.
1261 % The format of the GetPathComponent function is:
1263 % GetPathComponent(const char *path,PathType type,char *component)
1265 % A description of each parameter follows:
1267 % o path: Specifies a pointer to a character array that contains the
1270 % o type: Specififies which file path component to return.
1272 % o component: the selected file path component is returned here.
1275 MagickExport void GetPathComponent(const char *path,PathType type,
1279 magick[MaxTextExtent],
1281 subimage[MaxTextExtent];
1286 assert(path != (const char *) NULL);
1287 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",path);
1288 assert(component != (char *) NULL);
1294 (void) CopyMagickString(component,path,MaxTextExtent);
1296 #if defined(__OS2__)
1299 for (p=component; *p != '\0'; p++)
1301 if ((*p == '%') && (*(p+1) == '['))
1306 for (p++; (*p != ']') && (*p != '\0'); p++) ;
1310 if ((*p == ':') && (IsPathDirectory(path) < 0) &&
1311 (IsPathAccessible(path) == MagickFalse))
1314 Look for image format specification (e.g. ps3:image).
1316 (void) CopyMagickString(magick,component,(size_t) (p-component+1));
1317 if (IsMagickConflict(magick) != MagickFalse)
1320 for (q=component; *q != '\0'; q++)
1328 p=component+strlen(component)-1;
1329 if ((*p == ']') && (strchr(component,'[') != (char *) NULL) &&
1330 (IsPathAccessible(path) == MagickFalse))
1333 Look for scene specification (e.g. img0001.pcd[4]).
1335 for (q=p-1; q > component; q--)
1340 (void) CopyMagickString(subimage,q+1,MaxTextExtent);
1341 subimage[p-q-1]='\0';
1342 if ((IsSceneGeometry(subimage,MagickFalse) == MagickFalse) &&
1343 (IsGeometry(subimage) == MagickFalse))
1351 for (p=component+strlen(component)-1; p > component; p--)
1352 if (IsBasenameSeparator(*p) != MagickFalse)
1358 (void) CopyMagickString(component,magick,MaxTextExtent);
1363 for (p=component+(strlen(component)-1); p > component; p--)
1365 if (IsBasenameSeparator(*p) != MagickFalse)
1381 if (IsBasenameSeparator(*p) != MagickFalse)
1382 (void) CopyMagickMemory((unsigned char *) component,
1383 (const unsigned char *) (p+1),strlen(p+1)+1);
1388 if (IsBasenameSeparator(*p) != MagickFalse)
1389 (void) CopyMagickString(component,p+1,MaxTextExtent);
1390 for (p=component+(strlen(component)-1); p > component; p--)
1400 if (IsBasenameSeparator(*p) != MagickFalse)
1401 (void) CopyMagickString(component,p+1,MaxTextExtent);
1404 for (p=component+strlen(component)-1; p > component; p--)
1409 (void) CopyMagickString(component,p+1,MaxTextExtent);
1414 (void) CopyMagickString(component,subimage,MaxTextExtent);
1424 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1428 % G e t P a t h C o m p o n e n t s %
1432 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1434 % GetPathComponents() returns a list of path components.
1436 % The format of the GetPathComponents method is:
1438 % char **GetPathComponents(const char *path,
1439 % size_t *number_componenets)
1441 % A description of each parameter follows:
1443 % o path: Specifies the string to segment into a list.
1445 % o number_components: return the number of components in the list
1448 MagickExport char **GetPathComponents(const char *path,
1449 size_t *number_components)
1461 if (path == (char *) NULL)
1462 return((char **) NULL);
1463 *number_components=1;
1464 for (p=path; *p != '\0'; p++)
1465 if (IsBasenameSeparator(*p))
1466 (*number_components)++;
1467 components=(char **) AcquireQuantumMemory((size_t) *number_components+1UL,
1468 sizeof(*components));
1469 if (components == (char **) NULL)
1470 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1472 for (i=0; i < (ssize_t) *number_components; i++)
1474 for (q=p; *q != '\0'; q++)
1475 if (IsBasenameSeparator(*q))
1477 components[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+MaxTextExtent,
1478 sizeof(*components));
1479 if (components[i] == (char *) NULL)
1480 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1481 (void) CopyMagickString(components[i],p,(size_t) (q-p+1));
1484 components[i]=(char *) NULL;
1489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1493 % I s P a t h A c c e s s i b l e %
1497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1499 % IsPathAccessible() returns MagickTrue if the file as defined by the path is
1502 % The format of the IsPathAccessible method is:
1504 % MagickBooleanType IsPathAccessible(const char *filename)
1506 % A description of each parameter follows.
1508 % o path: Specifies a path to a file.
1511 MagickExport MagickBooleanType IsPathAccessible(const char *path)
1519 if ((path == (const char *) NULL) || (*path == '\0'))
1520 return(MagickFalse);
1521 status=GetPathAttributes(path,&attributes);
1522 if (status == MagickFalse)
1524 if (S_ISREG(attributes.st_mode) == 0)
1525 return(MagickFalse);
1526 if (access(path,F_OK) != 0)
1527 return(MagickFalse);
1532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1536 + I s P a t h D i r e c t o r y %
1540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1542 % IsPathDirectory() returns -1 if the directory does not exist, 1 is returned
1543 % if the path represents a directory otherwise 0.
1545 % The format of the IsPathDirectory method is:
1547 % int IsPathDirectory(const char *path)
1549 % A description of each parameter follows.
1551 % o path: The directory path.
1554 static int IsPathDirectory(const char *path)
1562 if ((path == (const char *) NULL) || (*path == '\0'))
1563 return(MagickFalse);
1564 status=GetPathAttributes(path,&attributes);
1565 if (status == MagickFalse)
1567 if (S_ISDIR(attributes.st_mode) == 0)
1573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1577 % I s M a g i c k T r u e %
1581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1583 % IsMagickTrue() returns MagickTrue if the value is "true", "on", "yes" or
1586 % The format of the IsMagickTrue method is:
1588 % MagickBooleanType IsMagickTrue(const char *value)
1590 % A description of each parameter follows:
1592 % o option: either MagickTrue or MagickFalse depending on the value
1595 % o value: Specifies a pointer to a character array.
1598 MagickExport MagickBooleanType IsMagickTrue(const char *value)
1600 if (value == (const char *) NULL)
1601 return(MagickFalse);
1602 if (LocaleCompare(value,"true") == 0)
1604 if (LocaleCompare(value,"on") == 0)
1606 if (LocaleCompare(value,"yes") == 0)
1608 if (LocaleCompare(value,"1") == 0)
1610 return(MagickFalse);
1614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1618 % L i s t F i l e s %
1622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1624 % ListFiles() reads the directory specified and returns a list of filenames
1625 % contained in the directory sorted in ascending alphabetic order.
1627 % The format of the ListFiles function is:
1629 % char **ListFiles(const char *directory,const char *pattern,
1630 % ssize_t *number_entries)
1632 % A description of each parameter follows:
1634 % o filelist: Method ListFiles returns a list of filenames contained
1635 % in the directory. If the directory specified cannot be read or it is
1636 % a file a NULL list is returned.
1638 % o directory: Specifies a pointer to a text string containing a directory
1641 % o pattern: Specifies a pointer to a text string containing a pattern.
1643 % o number_entries: This integer returns the number of filenames in the
1648 #if defined(__cplusplus) || defined(c_plusplus)
1652 static int FileCompare(const void *x,const void *y)
1658 p=(const char **) x;
1659 q=(const char **) y;
1660 return(LocaleCompare(*p,*q));
1663 #if defined(__cplusplus) || defined(c_plusplus)
1667 static inline int MagickReadDirectory(DIR *directory,struct dirent *entry,
1668 struct dirent **result)
1670 #if defined(MAGICKCORE_HAVE_READDIR_R)
1671 return(readdir_r(directory,entry,result));
1675 *result=readdir(directory);
1680 MagickExport char **ListFiles(const char *directory,const char *pattern,
1681 size_t *number_entries)
1699 assert(directory != (const char *) NULL);
1700 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",directory);
1701 assert(pattern != (const char *) NULL);
1702 assert(number_entries != (size_t *) NULL);
1704 current_directory=opendir(directory);
1705 if (current_directory == (DIR *) NULL)
1706 return((char **) NULL);
1711 filelist=(char **) AcquireQuantumMemory((size_t) max_entries,
1713 if (filelist == (char **) NULL)
1715 (void) closedir(current_directory);
1716 return((char **) NULL);
1719 Save the current and change to the new directory.
1721 buffer=(struct dirent *) AcquireAlignedMemory(1,sizeof(*buffer)+
1723 if (buffer == (struct dirent *) NULL)
1724 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1725 while ((MagickReadDirectory(current_directory,buffer,&entry) == 0) &&
1726 (entry != (struct dirent *) NULL))
1728 if (*entry->d_name == '.')
1730 if ((IsPathDirectory(entry->d_name) > 0) ||
1731 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1732 (GlobExpression(entry->d_name,pattern,MagickTrue) != MagickFalse))
1734 (GlobExpression(entry->d_name,pattern,MagickFalse) != MagickFalse))
1737 if (*number_entries >= max_entries)
1740 Extend the file list.
1743 filelist=(char **) ResizeQuantumMemory(filelist,(size_t)
1744 max_entries,sizeof(*filelist));
1745 if (filelist == (char **) NULL)
1753 p=strchr(entry->d_name,';');
1756 if (*number_entries > 0)
1757 if (LocaleCompare(entry->d_name,filelist[*number_entries-1]) == 0)
1761 filelist[*number_entries]=(char *) AcquireString(entry->d_name);
1762 (*number_entries)++;
1765 buffer=(struct dirent *) RelinquishMagickMemory(buffer);
1766 (void) closedir(current_directory);
1767 if (filelist == (char **) NULL)
1768 return((char **) NULL);
1770 Sort filelist in ascending order.
1772 qsort((void *) filelist,(size_t) *number_entries,sizeof(*filelist),
1778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1782 % M a g i c k D e l a y %
1786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1788 % MagickDelay() suspends program execution for the number of milliseconds
1791 % The format of the Delay method is:
1793 % void MagickDelay(const MagickSizeType milliseconds)
1795 % A description of each parameter follows:
1797 % o milliseconds: Specifies the number of milliseconds to delay before
1801 MagickExport void MagickDelay(const MagickSizeType milliseconds)
1803 if (milliseconds == 0)
1805 #if defined(MAGICKCORE_HAVE_NANOSLEEP)
1810 timer.tv_sec=(time_t) (milliseconds/1000);
1811 timer.tv_nsec=(milliseconds % 1000)*1000*1000;
1812 (void) nanosleep(&timer,(struct timespec *) NULL);
1814 #elif defined(MAGICKCORE_HAVE_USLEEP)
1815 usleep(1000*milliseconds);
1816 #elif defined(MAGICKCORE_HAVE_SELECT)
1821 timer.tv_sec=(long) milliseconds/1000;
1822 timer.tv_usec=(long) (milliseconds % 1000)*1000;
1823 (void) select(0,(XFD_SET *) NULL,(XFD_SET *) NULL,(XFD_SET *) NULL,&timer);
1825 #elif defined(MAGICKCORE_HAVE_POLL)
1826 (void) poll((struct pollfd *) NULL,0,(int) milliseconds);
1827 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
1828 Sleep((long) milliseconds);
1834 timer=milliseconds/1000.0;
1837 #elif defined(__BEOS__)
1838 snooze(1000*milliseconds);
1840 # error "Time delay method not defined."
1845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1849 % M u l t i l i n e C e n s u s %
1853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1855 % MultilineCensus() returns the number of lines within a label. A line is
1856 % represented by a \n character.
1858 % The format of the MultilineCenus method is:
1860 % size_t MultilineCensus(const char *label)
1862 % A description of each parameter follows.
1864 % o label: This character string is the label.
1868 MagickExport size_t MultilineCensus(const char *label)
1874 Determine the number of lines within this label.
1876 if (label == (char *) NULL)
1878 for (number_lines=1; *label != '\0'; label++)
1881 return(number_lines);
1885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1889 % O p e n M a g i c k S t r e a m %
1893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1895 % OpenMagickStream() opens the file at the specified path and return the
1896 % associated stream.
1898 % The path of the OpenMagickStream method is:
1900 % FILE *OpenMagickStream(const char *path,const char *mode)
1902 % A description of each parameter follows.
1904 % o path: the file path.
1906 % o mode: the file mode.
1909 MagickExport FILE *OpenMagickStream(const char *path,const char *mode)
1914 if ((path == (const char *) NULL) || (mode == (const char *) NULL))
1917 return((FILE *) NULL);
1920 #if defined(MAGICKCORE_HAVE__WFOPEN)
1926 unicode_path=ConvertUTF8ToUTF16((const unsigned char *) path);
1927 if (unicode_path == (wchar_t *) NULL)
1928 return((FILE *) NULL);
1929 unicode_mode=ConvertUTF8ToUTF16((const unsigned char *) mode);
1930 if (unicode_mode == (wchar_t *) NULL)
1932 unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path);
1933 return((FILE *) NULL);
1935 file=_wfopen(unicode_path,unicode_mode);
1936 unicode_mode=(wchar_t *) RelinquishMagickMemory(unicode_mode);
1937 unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path);
1940 if (file == (FILE *) NULL)
1941 file=fopen(path,mode);
1946 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1950 % S y s t e m C o m m a n d %
1954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1956 % SystemCommand() executes the specified command and waits until it
1957 % terminates. The returned value is the exit status of the command.
1959 % The format of the SystemCommand method is:
1961 % int SystemCommand(const MagickBooleanType asynchronous,
1962 % const MagickBooleanType verbose,const char *command,
1963 % ExceptionInfo *exception)
1965 % A description of each parameter follows:
1967 % o asynchronous: a value other than 0 executes the parent program
1968 % concurrently with the new child process.
1970 % o verbose: a value other than 0 prints the executed command before it is
1973 % o command: this string is the command to execute.
1975 % o exception: return any errors here.
1978 MagickExport int SystemCommand(const MagickBooleanType asynchronous,
1979 const MagickBooleanType verbose,const char *command,ExceptionInfo *exception)
1999 arguments=StringToArgv(command,&number_arguments);
2000 if (arguments == (char **) NULL)
2002 rights=ExecutePolicyRights;
2003 domain=DelegatePolicyDomain;
2004 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
2007 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
2008 "NotAuthorized","`%s'",arguments[1]);
2009 for (i=0; i < (ssize_t) number_arguments; i++)
2010 arguments[i]=DestroyString(arguments[i]);
2011 arguments=(char **) RelinquishMagickMemory(arguments);
2014 if (verbose != MagickFalse)
2016 (void) fprintf(stderr,"%s\n",command);
2017 (void) fflush(stderr);
2019 shell_command=(char *) command;
2020 if (asynchronous != MagickFalse)
2022 shell_command=AcquireString(command);
2023 (void) ConcatenateMagickString(shell_command,"&",MaxTextExtent);
2025 #if defined(MAGICKCORE_POSIX_SUPPORT)
2026 #if !defined(MAGICKCORE_HAVE_EXECVP)
2027 status=system(shell_command);
2029 if ((asynchronous != MagickFalse) || (strspn(shell_command,"&;<>|") == 0))
2030 status=system(shell_command);
2037 Call application directly rather than from a shell.
2040 if (child_pid == (pid_t) -1)
2041 status=system(command);
2045 status=execvp(arguments[1],arguments+1);
2057 pid=waitpid(child_pid,&child_status,0);
2062 if (WIFEXITED(child_status) != 0)
2063 status=WEXITSTATUS(child_status);
2065 if (WIFSIGNALED(child_status))
2071 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
2077 if (asynchronous != MagickFalse)
2079 status=spawnvp(mode,arguments[1],(const char **) (arguments+1));
2081 #elif defined(macintosh)
2082 status=MACSystemCommand(shell_command);
2084 status=system(shell_command);
2086 # error No suitable system() method.
2089 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
2090 "`%s' (%d)",command,status);
2091 if (shell_command != command)
2092 shell_command=DestroyString(shell_command);
2093 for (i=0; i < (ssize_t) number_arguments; i++)
2094 arguments[i]=DestroyString(arguments[i]);
2095 arguments=(char **) RelinquishMagickMemory(arguments);