18#ifndef MAGICKCORE_UTILITY_PRIVATE_H
19#define MAGICKCORE_UTILITY_PRIVATE_H
21#include "MagickCore/memory_.h"
22#include "MagickCore/nt-base.h"
23#include "MagickCore/nt-base-private.h"
24#if defined(MAGICKCORE_HAVE_UTIME_H)
27#if defined(__MINGW32__)
31#if defined(__cplusplus) || defined(c_plusplus)
35#define MagickPathTemplate "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
37extern MagickPrivate
char
38 **GetPathComponents(
const char *,
size_t *),
39 **ListFiles(
const char *,
const char *,
size_t *);
41extern MagickPrivate MagickBooleanType
42 GetExecutionPath(
char *,
const size_t),
43 ShredFile(
const char *);
45extern MagickPrivate ssize_t
46 GetMagickPageSize(
void);
48extern MagickPrivate
void
49 ChopPathComponents(
char *,
const size_t),
50 ExpandFilename(
char *);
52static inline int access_utf8(
const char *path,
int mode)
54 if (path == (
const char *) NULL)
56#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
57 return(access(path,mode));
59 return(NTAccessWide(path,mode));
63#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__)
64#define close_utf8 _close
66#define close_utf8 close
69static inline FILE *fopen_utf8(
const char *path,
const char *mode)
71#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
72 return(fopen(path,mode));
74 return(NTOpenFileWide(path,mode));
78static inline MagickBooleanType is_symlink_utf8(
const char *path)
80#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
81#if defined(MAGICKCORE_POSIX_SUPPORT)
85 if (lstat(path,&status) == -1)
87 return(S_ISLNK(status.st_mode) != 0 ? MagickTrue : MagickFalse);
92 return(NTIsSymlinkWide(path));
96static inline ssize_t MagickRead(
int fd,
void *buffer,
size_t extent)
98 unsigned char *p = (
unsigned char *) buffer;
100 while (offset < extent)
102 ssize_t count = read(fd,p+offset,extent-offset);
111 offset+=(size_t) count;
113 return((ssize_t) offset);
116static inline int MagickReadDirectory(DIR *directory,
struct dirent *entry,
117 struct dirent **result)
121 *result=readdir(directory);
125static inline ssize_t MagickWrite(
int fd,
const void *buffer,
size_t extent)
127 const unsigned char *p = (
const unsigned char *) buffer;
129 while (offset < extent)
131 ssize_t count = write(fd,p+offset,extent-offset);
139 offset+=(size_t) count;
141 return((ssize_t) offset);
144static inline int open_utf8(
const char *path,
int flags,mode_t mode)
146#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
147 return(open(path,flags,mode));
149 return(NTOpenWide(path,flags,mode));
153static inline FILE *popen_utf8(
const char *command,
const char *type)
155#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
156 return(popen(command,type));
158 return(NTOpenPipeWide(command,type));
162static inline char *realpath_utf8(
const char *path)
164#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
165#if defined(MAGICKCORE_HAVE_REALPATH)
170 return(realpath(path,(
char *) NULL));
172 return(AcquireString(path));
175 return(NTRealPathWide(path));
179static inline int remove_utf8(
const char *path)
181#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
182 return(unlink(path));
184 return(NTRemoveWide(path));
188static inline int rename_utf8(
const char *source,
const char *destination)
190#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
191 return(rename(source,destination));
193 return(NTRenameWide(source,destination));
197static inline int set_file_timestamp(
const char *path,
struct stat *attributes)
202#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
203#if defined(MAGICKCORE_HAVE_UTIMENSAT)
204#if defined(__APPLE__) || defined(__NetBSD__)
205#define st_atim st_atimespec
206#define st_ctim st_ctimespec
207#define st_mtim st_mtimespec
213 timestamp[0].tv_sec=attributes->st_atim.tv_sec;
214 timestamp[0].tv_nsec=attributes->st_atim.tv_nsec;
215 timestamp[1].tv_sec=attributes->st_mtim.tv_sec;
216 timestamp[1].tv_nsec=attributes->st_mtim.tv_nsec;
217 status=utimensat(AT_FDCWD,path,timestamp,0);
222 timestamp.actime=attributes->st_atime;
223 timestamp.modtime=attributes->st_mtime;
224 status=utime(path,×tamp);
227 status=NTSetFileTimestamp(path,attributes);
232static inline int stat_utf8(
const char *path,
struct stat *attributes)
234#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
235 return(stat(path,attributes));
237 return(NTStatWide(path,attributes));
241#if defined(__cplusplus) || defined(c_plusplus)