69 #if defined(MAGICKCORE_HAVE_PROCESS_H)
72 #if defined(MAGICKCORE_HAVE_MACH_O_DYLD_H)
73 #include <mach-o/dyld.h>
80 Base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
176 assert(source != (
const char *) NULL);
177 assert(destination != (
char *) NULL);
178 #if defined(MAGICKCORE_HAVE_SYMLINK)
186 if (passes != (
char *) NULL)
192 if (symlink(source,destination) == 0)
206 if (symlink(path,destination) == 0)
213 if (destination_file == -1)
216 if (source_file == -1)
218 (void) close(destination_file);
223 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
226 if (buffer == (
unsigned char *) NULL)
228 (void) close(source_file);
229 (void) close(destination_file);
236 count=(ssize_t) read(source_file,buffer,quantum);
239 length=(size_t) count;
240 count=(ssize_t) write(destination_file,buffer,length);
241 if ((
size_t) count != length)
248 (void) close(destination_file);
249 (void) close(source_file);
287 assert(format != (
char *) NULL);
288 assert(filename != (
char *) NULL);
290 if ((*format ==
'\0') || (*filename ==
'\0'))
362 assert(source != (
char *) NULL);
363 assert(length != (
size_t *) NULL);
367 if (decode == (
unsigned char *) NULL)
368 return((
unsigned char *) NULL);
371 for (p=source; *p !=
'\0'; p++)
373 if (isspace((
int) ((
unsigned char) *p)) != 0)
378 if (q == (
char *) NULL)
381 return((
unsigned char *) NULL);
387 decode[i]=(q-
Base64) << 2;
393 decode[i++]|=(q-
Base64) >> 4;
394 decode[i]=((q-
Base64) & 0x0f) << 4;
400 decode[i++]|=(q-
Base64) >> 2;
401 decode[i]=((q-
Base64) & 0x03) << 6;
421 return((
unsigned char *) NULL);
436 return((
unsigned char *) NULL);
440 for ( ; *p !=
'\0'; p++)
441 if (isspace((
int) ((
unsigned char) *p)) == 0)
446 return((
unsigned char *) NULL);
452 for ( ; *p !=
'\0'; p++)
453 if (isspace((
int) ((
unsigned char) *p)) == 0)
456 return((
unsigned char *) NULL);
458 if ((
int) decode[i] != 0)
461 return((
unsigned char *) NULL);
502 const size_t blob_length,
size_t *encode_length)
507 register const unsigned char
517 assert(blob != (
const unsigned char *) NULL);
518 assert(blob_length != 0);
519 assert(encode_length != (
size_t *) NULL);
522 if (encode == (
char *) NULL)
523 return((
char *) NULL);
525 for (p=blob; p < (blob+blob_length-2); p+=3)
527 encode[i++]=
Base64[(int) (*p >> 2)];
528 encode[i++]=
Base64[(int) (((*p & 0x03) << 4)+(*(p+1) >> 4))];
529 encode[i++]=
Base64[(int) (((*(p+1) & 0x0f) << 2)+(*(p+2) >> 6))];
530 encode[i++]=
Base64[(int) (*(p+2) & 0x3f)];
532 remainder=blob_length % 3;
544 for (j=0; j < (ssize_t) remainder; j++)
546 encode[i++]=
Base64[(int) (code[0] >> 2)];
547 encode[i++]=
Base64[(int) (((code[0] & 0x03) << 4)+(code[1] >> 4))];
551 encode[i++]=
Base64[(int) (((code[1] & 0x0f) << 2)+(code[2] >> 6))];
589 for (i=0; i < (ssize_t) components; i++)
621 if (path == (
char *) NULL)
637 if (home == (
char *) NULL)
639 if (home != (
char *) NULL)
648 #if defined(MAGICKCORE_POSIX_SUPPORT) && !defined(__OS2__)
662 p=strchr(username,
'/');
663 if (p != (
char *) NULL)
665 entry=getpwnam(username);
666 if (entry == (
struct passwd *) NULL)
669 if (p != (
char *) NULL)
757 assert(number_arguments != (
int *) NULL);
758 assert(arguments != (
char ***) NULL);
761 if (vector == (
char **) NULL)
766 *home_directory=
'\0';
768 for (i=0; i < (ssize_t) *number_arguments; i++)
781 option=(*arguments)[i];
795 for (j=0; j < parameters; j++)
798 if (i == (ssize_t) *number_arguments)
800 option=(*arguments)[i];
805 if ((*option ==
'"') || (*option ==
'\''))
824 if (*home_directory ==
'\0')
826 filelist=
ListFiles(*path ==
'\0' ? home_directory : path,filename,
846 if (files == (
char *) NULL)
849 if (filelist == (
char **) NULL)
853 for (j=0; j < (ssize_t) (length-1); j++)
854 filelist[j]=filelist[j+1];
855 number_files=(size_t) length-1;
857 if (filelist == (
char **) NULL)
859 for (j=0; j < (ssize_t) number_files; j++)
862 if (j == (ssize_t) number_files)
864 for (j=0; j < (ssize_t) number_files; j++)
873 count+number_files+1,
sizeof(*vector));
874 if (vector == (
char **) NULL)
876 for (j=0; j < (ssize_t) number_files; j++)
881 for (j=0; j < (ssize_t) number_files; j++)
894 for (k=0; k < parameters; k++)
897 if (j == (ssize_t) number_files)
908 if (filelist[j] != (
char *) NULL)
926 if (*subimage !=
'\0')
946 vector[count]=(
char *) NULL;
953 for (i=1; i < count; i++)
960 "Command line: %s",command_line);
963 *number_arguments=(int) count;
999 directory=getcwd(path,(
unsigned long) extent);
1001 #if defined(MAGICKCORE_HAVE_GETPID) && defined(MAGICKCORE_HAVE_READLINK) && defined(PATH_MAX)
1012 count=readlink(link_path,execution_path,
PATH_MAX);
1017 count=readlink(link_path,execution_path,
PATH_MAX);
1019 if ((count > 0) && (count <= (ssize_t)
PATH_MAX))
1021 execution_path[count]=
'\0';
1026 #if defined(MAGICKCORE_HAVE__NSGETEXECUTABLEPATH)
1035 length=
sizeof(executable_path);
1036 if ((_NSGetExecutablePath(executable_path,&length) == 0) &&
1037 (realpath(executable_path,execution_path) != (
char *) NULL))
1041 #if defined(MAGICKCORE_HAVE_GETEXECNAME)
1046 execution_path=(
const char *) getexecname();
1047 if (execution_path != (
const char *) NULL)
1055 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1056 NTGetExecutionPath(path,extent);
1058 #if defined(__GNU__)
1067 program_name=program_invocation_name;
1068 if (*program_invocation_name !=
'/')
1073 extent=strlen(directory)+strlen(program_name)+2;
1075 if (program_name == (
char *) NULL)
1076 program_name=program_invocation_name;
1079 program_invocation_name);
1086 if (realpath(program_name,execution_path) != (
char *) NULL)
1089 if (program_name != program_invocation_name)
1093 #if defined(__OpenBSD__)
1129 #if defined(MAGICKCORE_HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
1130 page_size=(ssize_t) sysconf(_SC_PAGE_SIZE);
1131 #elif defined(MAGICKCORE_HAVE_GETPAGESIZE)
1132 page_size=(ssize_t) getpagesize();
1133 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
1134 page_size=NTGetPageSize();
1171 if (path == (
const char *) NULL)
1176 (void) memset(attributes,0,
sizeof(
struct stat));
1227 assert(path != (
const char *) NULL);
1229 assert(component != (
char *) NULL);
1240 p=component+strlen(component)-1;
1241 q=strrchr(component,
'[');
1242 if ((strlen(component) > 2) && (*p ==
']') && (q != (
char *) NULL) &&
1243 ((q == component) || (*(q-1) !=
']')) &&
1255 subimage_length=(size_t) (p-q);
1256 subimage_offset=(size_t) (q-component+1);
1262 #if defined(__OS2__)
1265 for (p=component; *p !=
'\0'; p++)
1267 if ((*p ==
'%') && (*(p+1) ==
'['))
1272 for (p++; (*p !=
']') && (*p !=
'\0'); p++) ;
1276 if ((p != component) && (*p ==
':') && (
IsPathDirectory(component) < 0) &&
1287 magick_length=(size_t) (p-component+1);
1288 for (q=component; *(++p) !=
'\0'; q++)
1297 for (p=component+strlen(component)-1; p > component; p--)
1304 if (magick_length != 0)
1312 if (*component !=
'\0')
1314 for (p=component+(strlen(component)-1); p > component; p--)
1341 if (*component !=
'\0')
1342 for (p=component+(strlen(component)-1); p > component; p--)
1354 if (*component !=
'\0')
1355 for (p=component+strlen(component)-1; p > component; p--)
1366 if ((subimage_length != 0) && (magick_length < subimage_offset))
1403 size_t *number_components)
1415 if (path == (
char *) NULL)
1416 return((
char **) NULL);
1417 *number_components=1;
1418 for (p=path; *p !=
'\0'; p++)
1420 (*number_components)++;
1422 sizeof(*components));
1423 if (components == (
char **) NULL)
1426 for (i=0; i < (ssize_t) *number_components; i++)
1428 for (q=p; *q !=
'\0'; q++)
1432 sizeof(**components));
1433 if (components[i] == (
char *) NULL)
1438 components[i]=(
char *) NULL;
1473 if ((path == (
const char *) NULL) || (*path ==
'\0'))
1480 if (
S_ISREG(attributes.st_mode) == 0)
1518 if ((path == (
const char *) NULL) || (*path ==
'\0'))
1523 if (
S_ISDIR(attributes.st_mode) == 0)
1563 #if defined(__cplusplus) || defined(c_plusplus)
1573 p=(
const char **) x;
1574 q=(
const char **) y;
1578 #if defined(__cplusplus) || defined(c_plusplus)
1583 size_t *number_entries)
1601 assert(directory != (
const char *) NULL);
1603 assert(pattern != (
const char *) NULL);
1604 assert(number_entries != (
size_t *) NULL);
1606 current_directory=
opendir(directory);
1607 if (current_directory == (
DIR *) NULL)
1608 return((
char **) NULL);
1615 if (filelist == (
char **) NULL)
1617 (void)
closedir(current_directory);
1618 return((
char **) NULL);
1624 if (buffer == (
struct dirent *) NULL)
1627 (entry != (
struct dirent *) NULL))
1629 if (*entry->
d_name ==
'.')
1632 #
if defined(MAGICKCORE_WINDOWS_SUPPORT)
1638 if (*number_entries >= max_entries)
1645 max_entries,
sizeof(*filelist));
1646 if (filelist == (
char **) NULL)
1654 p=strchr(entry->
d_name,
';');
1657 if (*number_entries > 0)
1663 (*number_entries)++;
1667 (void)
closedir(current_directory);
1668 if (filelist == (
char **) NULL)
1669 return((
char **) NULL);
1673 qsort((
void *) filelist,(
size_t) *number_entries,
sizeof(*filelist),
1704 if (milliseconds == 0)
1706 #if defined(MAGICKCORE_HAVE_NANOSLEEP)
1711 timer.tv_sec=(time_t) (milliseconds/1000);
1712 timer.tv_nsec=(milliseconds % 1000)*1000*1000;
1713 (void) nanosleep(&timer,(
struct timespec *) NULL);
1715 #elif defined(MAGICKCORE_HAVE_USLEEP)
1716 usleep(1000*milliseconds);
1717 #elif defined(MAGICKCORE_HAVE_SELECT)
1722 timer.tv_sec=(long) milliseconds/1000;
1723 timer.tv_usec=(long) (milliseconds % 1000)*1000;
1724 (void) select(0,(XFD_SET *) NULL,(XFD_SET *) NULL,(XFD_SET *) NULL,&timer);
1726 #elif defined(MAGICKCORE_HAVE_POLL)
1727 (void) poll((
struct pollfd *) NULL,0,(int) milliseconds);
1728 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
1729 Sleep((
long) milliseconds);
1735 timer=milliseconds/1000.0;
1738 #elif defined(__BEOS__)
1739 snooze(1000*milliseconds);
1741 # error "Time delay method not defined."
1776 if (label == (
char *) NULL)
1778 for (number_lines=1; *label !=
'\0'; label++)
1781 return(number_lines);
1830 if ((path == (
const char *) NULL) || (*path ==
'\0'))
1833 if (passes == (
char *) NULL)
1835 if (passes == (
char *) NULL)
1844 "Failed to remove: %s",path);
1859 "Failed to remove: %s",path);
1866 if ((fstat(file,&file_stats) == 0) && (file_stats.st_size > 0))
1880 if (lseek(file,0,SEEK_SET) < 0)
MagickExport MagickBooleanType GetPathAttributes(const char *path, void *attributes)
static const char Base64[]
#define IsBasenameSeparator(c)
MagickExport ssize_t ParseCommandOption(const CommandOption option, const MagickBooleanType list, const char *options)
#define ThrowFatalException(severity, tag)
static int StringToInteger(const char *magick_restrict value)
MagickExport size_t ConcatenateMagickString(char *destination, const char *source, const size_t length)
#define MagickMaxBufferExtent
MagickPrivate MagickBooleanType IsMagickConflict(const char *)
MagickExport ExceptionInfo * AcquireExceptionInfo(void)
MagickExport ssize_t FormatLocaleString(char *magick_restrict string, const size_t length, const char *magick_restrict format,...)
static void getcwd_utf8(char *path, size_t extent)
MagickExport void * ResizeQuantumMemory(void *memory, const size_t count, const size_t quantum)
MagickExport MagickBooleanType AcquireUniqueFilename(char *path)
MagickExport char * FileToString(const char *filename, const size_t extent, ExceptionInfo *exception)
static int stat_utf8(const char *path, struct stat *attributes)
MagickExport RandomInfo * DestroyRandomInfo(RandomInfo *random_info)
static int IsPathDirectory(const char *)
MagickExport unsigned char * GetStringInfoDatum(const StringInfo *string_info)
MagickExport size_t MultilineCensus(const char *label)
MagickExport MagickBooleanType IsGeometry(const char *geometry)
MagickExport void GetPathComponent(const char *path, PathType type, char *component)
#define DirectorySeparator
MagickExport char * AcquireString(const char *source)
MagickExport int AcquireUniqueFileResource(char *path)
MagickPrivate ssize_t GetMagickPageSize(void)
static int remove_utf8(const char *path)
MagickExport StringInfo * DestroyStringInfo(StringInfo *string_info)
MagickExport void ResetStringInfo(StringInfo *string_info)
MagickExport unsigned char * Base64Decode(const char *source, size_t *length)
MagickPrivate void ExpandFilename(char *)
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
MagickExport MagickBooleanType RelinquishUniqueFileResource(const char *path)
MagickExport char * Base64Encode(const unsigned char *blob, const size_t blob_length, size_t *encode_length)
MagickExport MagickBooleanType ConcatenateString(char **destination, const char *source)
MagickPrivate MagickBooleanType IsGlob(const char *) magick_attribute((__pure__))
MagickExport MagickBooleanType GlobExpression(const char *expression, const char *pattern, const MagickBooleanType case_insensitive)
MagickExport void MagickDelay(const MagickSizeType milliseconds)
MagickExport MagickBooleanType IsEventLogging(void)
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
MagickExport MagickBooleanType IsPathAccessible(const char *path)
static int open_utf8(const char *path, int flags, mode_t mode)
MagickExport RandomInfo * AcquireRandomInfo(void)
MagickExport MagickBooleanType AcquireUniqueSymbolicLink(const char *source, char *destination)
MagickExport char * GetEnvironmentValue(const char *name)
MagickExport size_t CopyMagickString(char *destination, const char *source, const size_t length)
MagickPrivate MagickBooleanType ShredFile(const char *)
MagickPrivate char ** GetPathComponents(const char *, size_t *)
MagickExport void AppendImageFormat(const char *format, char *filename)
MagickExport int LocaleCompare(const char *p, const char *q)
#define GetMagickModule()
MagickPrivate char ** ListFiles(const char *, const char *, size_t *)
MagickExport MagickBooleanType ExpandFilenames(int *number_arguments, char ***arguments)
MagickPrivate MagickBooleanType GetExecutionPath(char *, const size_t)
MagickExport char * DestroyString(char *string)
MagickExport void * AcquireMagickMemory(const size_t size)
static int access_utf8(const char *path, int mode)
static int MagickReadDirectory(DIR *directory, struct dirent *entry, struct dirent **result)
MagickExport char * GetPolicyValue(const char *name)
static RandomInfo * random_info
MagickExport void * RelinquishMagickMemory(void *memory)
MagickPrivate void ChopPathComponents(char *, const size_t)
static int FileCompare(const void *x, const void *y)
MagickExport StringInfo * GetRandomKey(RandomInfo *random_info, const size_t length)
MagickExport char ** StringToArgv(const char *text, int *argc)
MagickExport MagickBooleanType IsSceneGeometry(const char *geometry, const MagickBooleanType pedantic)
MagickExport char * ConstantString(const char *source)
MagickExport ExceptionInfo * DestroyExceptionInfo(ExceptionInfo *exception)