18#ifndef _WIZARDSTOOLKIT_UTILITY_PRIVATE_H
19#define _WIZARDSTOOLKIT_UTILITY_PRIVATE_H
22#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
26#define WizardMax(x,y) (((x) > (y)) ? (x) : (y))
27#define WizardMin(x,y) (((x) < (y)) ? (x) : (y))
29#if defined(__cplusplus) || defined(c_plusplus)
52#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
53 return(access(path,mode));
62 path_wide=(WCHAR *) NULL;
63 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
65 if (path_wide == (WCHAR *) NULL)
67 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
68 status=_waccess(path_wide,mode);
74static inline FILE *
fopen_utf8(
const char *path,
const char *mode)
76#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
77 return(fopen(path,mode));
89 path_wide=(WCHAR *) NULL;
90 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
92 if (path_wide == (WCHAR *) NULL)
93 return((FILE *) NULL);
94 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
95 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,NULL,0);
97 if (mode_wide == (WCHAR *) NULL)
100 return((FILE *) NULL);
102 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,mode_wide,count);
103 file=_wfopen(path_wide,mode_wide);
110#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__)
115static inline int open_utf8(
const char *path,
int flags,mode_t mode)
117#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
118 return(open(path,flags,mode));
127 path_wide=(WCHAR *) NULL;
128 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
130 if (path_wide == (WCHAR *) NULL)
132 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
133 status=_wopen(path_wide,flags,mode);
139static inline FILE *
popen_utf8(
const char *command,
const char *type)
141#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
142 return(popen(command,type));
154 command_wide=(WCHAR *) NULL;
155 count=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
157 if (command_wide == (WCHAR *) NULL)
158 return((FILE *) NULL);
159 count=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,count);
160 count=MultiByteToWideChar(CP_UTF8,0,type,-1,NULL,0);
162 if (type_wide == (WCHAR *) NULL)
165 return((FILE *) NULL);
167 count=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,count);
168 file=_wpopen(command_wide,type_wide);
177#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
178 return(unlink(path));
187 path_wide=(WCHAR *) NULL;
188 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
190 if (path_wide == (WCHAR *) NULL)
192 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
193 status=_wremove(path_wide);
199static inline int rename_utf8(
const char *source,
const char *destination)
201#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
202 return(rename(source,destination));
212 source_wide=(WCHAR *) NULL;
213 count=MultiByteToWideChar(CP_UTF8,0,source,-1,NULL,0);
215 if (source_wide == (WCHAR *) NULL)
217 count=MultiByteToWideChar(CP_UTF8,0,source,-1,source_wide,count);
218 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,NULL,0);
220 sizeof(*destination_wide));
221 if (destination_wide == (WCHAR *) NULL)
226 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,destination_wide,count);
227 status=_wrename(source_wide,destination_wide);
234static inline int stat_utf8(
const char *path,
struct stat *attributes)
236#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
237 return(stat(path,attributes));
246 path_wide=(WCHAR *) NULL;
247 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
249 if (path_wide == (WCHAR *) NULL)
251 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
252 status=_wstat64(path_wide,attributes);
258#if defined(__cplusplus) || defined(c_plusplus)
WizardExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
WizardExport void * RelinquishWizardMemory(void *memory)
static int open_utf8(const char *path, int flags, mode_t mode)
static FILE * fopen_utf8(const char *path, const char *mode)
WizardExport void ChopPathComponents(char *, const size_t)
WizardPrivate ssize_t GetWizardPageSize(void)
static int remove_utf8(const char *path)
static int access_utf8(const char *path, int mode)
static int stat_utf8(const char *path, struct stat *attributes)
WizardExport char ** GetPathComponents(const char *, size_t *)
static int rename_utf8(const char *source, const char *destination)
WizardExport WizardBooleanType GetExecutionPath(char *, const size_t)
WizardExport void WizardDelay(const WizardSizeType)
static FILE * popen_utf8(const char *command, const char *type)