51#if defined(WIZARDSTOOLKIT_HAVE_MACH_O_DYLD_H)
52#include <mach-o/dyld.h>
59 Base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
99 assert(extension != (
char *) NULL);
100 assert(filename != (
char *) NULL);
102 if ((*extension ==
'\0') || (*filename ==
'\0'))
152 assert(source != (
char *) NULL);
153 assert(length != (
size_t *) NULL);
157 if (decode == (
unsigned char *) NULL)
158 return((
unsigned char *) NULL);
161 for (p=source; *p !=
'\0'; p++)
163 if (isspace((
int) ((
unsigned char) *p)) != 0)
168 if (q == (
char *) NULL)
171 return((
unsigned char *) NULL);
177 decode[i]=(q-
Base64) << 2;
183 decode[i++]|=(q-
Base64) >> 4;
184 decode[i]=((q-
Base64) & 0x0f) << 4;
190 decode[i++]|=(q-
Base64) >> 2;
191 decode[i]=((q-
Base64) & 0x03) << 6;
211 return((
unsigned char *) NULL);
226 return((
unsigned char *) NULL);
230 for ( ; *p !=
'\0'; p++)
231 if (isspace((
int) ((
unsigned char) *p)) == 0)
236 return((
unsigned char *) NULL);
242 for ( ; *p !=
'\0'; p++)
243 if (isspace((
int) ((
unsigned char) *p)) == 0)
246 return((
unsigned char *) NULL);
248 if ((
int) decode[i] != 0)
251 return((
unsigned char *) NULL);
293 const size_t blob_length,
size_t *encode_length)
309 assert(blob != (
const unsigned char *) NULL);
310 assert(blob_length != 0);
311 assert(encode_length != (
size_t *) NULL);
313 quantum=4*blob_length/3+4;
315 if (encode == (
char *) NULL)
316 return((
char *) NULL);
318 for (p=blob; p < (blob+blob_length-2); p+=3)
320 encode[i++]=
Base64[(int) (*p >> 2)];
321 encode[i++]=
Base64[(int) (((*p & 0x03) << 4)+(*(p+1) >> 4))];
322 encode[i++]=
Base64[(int) (((*(p+1) & 0x0f) << 2)+(*(p+2) >> 6))];
323 encode[i++]=
Base64[(int) (*(p+2) & 0x3f)];
325 remainder=blob_length % 3;
337 for (j=0; j < (ssize_t) remainder; j++)
339 encode[i++]=
Base64[(int) (code[0] >> 2)];
340 encode[i++]=
Base64[(int) (((code[0] & 0x03) << 4)+(code[1] >> 4))];
344 encode[i++]=
Base64[(int) (((code[1] & 0x0f) << 2)+(code[2] >> 6))];
349 assert(i <= quantum);
383 for (i=0; i < (ssize_t) components; i++)
429 assert(path != (
const char *) NULL);
431 assert(component != (
const char *) NULL);
439 for (p=component; *p !=
'\0'; p++)
451 for (q=component; *q !=
'\0'; q++)
458 p=component+strlen(component)-1;
459 if ((*p ==
']') && (strchr(component,
'[') != (
char *) NULL))
464 for (q=p-1; q > component; q--)
476 for (p=component+(strlen(component)-1); p > component; p--)
488 for (p=component+(strlen(component)-1); p > component; p--)
508 (
const unsigned char *) (p+1),strlen(p+1)+1);
515 for (p=component+(strlen(component)-1); p > component; p--)
529 for (p=component+strlen(component)-1; p > component; p--)
535 p=strchr(component,
'?');
536 if (p != (
char *) NULL)
577 size_t *number_components)
591 if (path == (
char *) NULL)
592 return((
char **) NULL);
593 *number_components=1;
594 for (p=path; *p !=
'\0'; p++)
596 (*number_components)++;
598 sizeof(*components));
599 if (components == (
char **) NULL)
602 for (i=0; i < (ssize_t) *number_components; i++)
604 for (q=(
char *) p; *q !=
'\0'; q++)
608 sizeof(**components));
609 if (components[i] == (
char *) NULL)
614 components[i]=(
char *) NULL;
649 directory=getcwd(path,(
unsigned long) extent);
651#if defined(WIZARDSTOOLKIT_HAVE_GETPID) && defined(WIZARDSTOOLKIT_HAVE_READLINK) && defined(PATH_MAX)
662 length=readlink(link_path,real_path,
PATH_MAX);
667 length=readlink(link_path,real_path,
PATH_MAX);
669 if ((length > 0) && ((
size_t) length <=
PATH_MAX))
671 real_path[length]=
'\0';
676#if defined(WIZARDSTOOLKIT_HAVE__NSGETEXECUTABLEPATH)
686 length=
sizeof(executable_path);
687 if ((_NSGetExecutablePath(executable_path,&length) == 0) &&
688 (realpath(executable_path,real_path) != (
char *) NULL))
692#if defined(WIZARDSTOOLKIT_HAVE_GETEXECNAME)
697 execution_path=(
const char *) getexecname();
698 if (execution_path != (
const char *) NULL)
706#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
707 NTGetExecutionPath(path,extent);
719 execution_path=(
char *) NULL;
720 program_name=program_invocation_name;
721 if (*program_invocation_name !=
'/')
726 extent=strlen(directory)+strlen(program_name)+2;
728 if (program_name == (
char *) NULL)
729 program_name=program_invocation_name;
732 program_invocation_name);
736 execution_path=realpath(program_name,NULL);
737 if (execution_path != (
char *) NULL)
740 if (program_name != program_invocation_name)
745#if defined(__OpenBSD__)
750 (void) CopyMagickString(path,__progname,extent);
787 if ((path == (
const char *) NULL) || (*path ==
'\0'))
792 if (
S_ISREG(file_info.st_mode) == 0)
794 if (access(path,F_OK) != 0)
824#if defined(WIZARDSTOOLKIT_HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
825 page_size=(ssize_t) sysconf(_SC_PAGE_SIZE);
827#if defined(WIZARDSTOOLKIT_HAVE_GETPAGESIZE)
828 page_size=(ssize_t) getpagesize();
872 if ((path == (
const char *) NULL) || (*path ==
'\0'))
877 if (
S_ISDIR(file_info.st_mode) == 0)
879 if (access(path,
X_OK) != 0)
912 if (value == (
char *) NULL)
969 separators[] =
"--T::-:";
976 *target=time((time_t *) NULL);
977#if defined(WIZARDSTOOLKIT_HAVE_LOCALTIME_R)
978 (void) localtime_r(target,&local_time);
980 (void) memcpy(&local_time,localtime(target),
sizeof(local_time));
982#if defined(WIZARDSTOOLKIT_HAVE_GMTIME_R)
983 (void) gmtime_r(target,&gm_time);
985 (void) memcpy(&gm_time,gmtime(target),
sizeof(gm_time));
987 timezone=(ssize_t) ((local_time.tm_min-gm_time.tm_min)/60+local_time.tm_hour-
988 gm_time.tm_hour+24*((local_time.tm_year-gm_time.tm_year) != 0 ?
989 (local_time.tm_year-gm_time.tm_year) : (local_time.tm_yday-
991 (void) memset(&target_time,0,
sizeof(target_time));
996 if (*q != separators[i])
1000 case 0: target_time.tm_year=(int) (value+0.5)-1900;
break;
1001 case 1: target_time.tm_mon=(int) (value+0.5)-1;
break;
1002 case 2: target_time.tm_mday=(int) (value+0.5);
break;
1003 case 3: target_time.tm_hour=(int) (value+0.5);
break;
1004 case 4: target_time.tm_min=(int) (value+0.5);
break;
1005 case 5: target_time.tm_sec=(int) (value+0.5);
break;
1006 case 6: timezone+=(int) (value+0.5);
break;
1014 *target=mktime(&target_time)-3600*timezone;
1044 if (milliseconds == 0)
1046#if defined(WIZARDSTOOLKIT_HAVE_NANOSLEEP)
1051 timer.tv_sec=(time_t) (milliseconds/1000);
1052 timer.tv_nsec=(milliseconds % 1000)*1000*1000;
1053 (void) nanosleep(&timer,(
struct timespec *) NULL);
1055#elif defined(WIZARDSTOOLKIT_HAVE_USLEEP)
1056 usleep(1000*milliseconds);
1057#elif defined(WIZARDSTOOLKIT_HAVE_SELECT)
1062 timer.tv_sec=(long) milliseconds/1000;
1063 timer.tv_usec=(long) (milliseconds % 1000)*1000;
1064 (void) select(0,(XFD_SET *) NULL,(XFD_SET *) NULL,(XFD_SET *) NULL,&timer);
1066#elif defined(WIZARDSTOOLKIT_HAVE_POLL)
1067 (void) poll((
struct pollfd *) NULL,0,(int) milliseconds);
1068#elif defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
1069 Sleep((
long) milliseconds);
1075 timer=milliseconds/1000.0;
1078#elif defined(__BEOS__)
1079 snooze(1000*milliseconds);
1081# error "Time delay method not defined."
#define ThrowFatalException(severity, tag)
WizardExport ssize_t FormatLocaleString(char *string, const size_t length, const char *format,...)
WizardBooleanType LogWizardEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
#define GetWizardModule()
WizardExport void * CopyWizardMemory(void *destination, const void *source, const size_t size)
WizardExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
WizardExport void * RelinquishWizardMemory(void *memory)
static double StringToDouble(const char *string, char **sentinal)
WizardExport int LocaleCompare(const char *p, const char *q)
WizardExport size_t ConcatenateWizardString(char *destination, const char *source, const size_t length)
WizardExport size_t CopyWizardString(char *destination, const char *source, const size_t length)
#define IsBasenameSeparator(c)
#define DirectorySeparator
static int stat_utf8(const char *path, struct stat *attributes)
WizardExport WizardBooleanType IsWizardTrue(const char *value)
WizardExport void AppendFileExtension(const char *extension, char *filename)
WizardExport void GetPathComponent(const char *path, PathType type, char *component)
WizardExport WizardBooleanType GetExecutionPath(char *path, const size_t extent)
WizardExport void ChopPathComponents(char *path, const size_t components)
WizardPrivate ssize_t GetWizardPageSize(void)
WizardExport char ** GetPathComponents(const char *path, size_t *number_components)
WizardExport WizardBooleanType IsPathAcessible(const char *path)
WizardExport char * Base64Encode(const unsigned char *blob, const size_t blob_length, size_t *encode_length)
static const char Base64[]
static int IsDirectory(const char *)
WizardExport void WizardDelay(const WizardSizeType milliseconds)
WizardExport const char * ParseWizardTime(const char *timestamp, time_t *target)
WizardExport unsigned char * Base64Decode(const char *source, size_t *length)