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);
145static inline int open_utf8(
const char *path,
int flags,mode_t mode)
147#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
148 return(open(path,flags,mode));
150 return(NTOpenWide(path,flags,mode));
154static inline FILE *popen_utf8(
const char *command,
const char *type)
156#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
157 return(popen(command,type));
159 return(NTOpenPipeWide(command,type));
163static inline char *realpath_utf8(
const char *path)
165#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
166#if defined(MAGICKCORE_HAVE_REALPATH)
171 return(realpath(path,(
char *) NULL));
173 return(AcquireString(path));
176 return(NTRealPathWide(path));
180static inline int remove_utf8(
const char *path)
182#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
183 return(unlink(path));
185 return(NTRemoveWide(path));
189static inline int rename_utf8(
const char *source,
const char *destination)
191#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
192 return(rename(source,destination));
194 return(NTRenameWide(source,destination));
198static inline int set_file_timestamp(
const char *path,
struct stat *attributes)
203#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
204#if defined(MAGICKCORE_HAVE_UTIMENSAT)
205#if defined(__APPLE__) || defined(__NetBSD__)
206#define st_atim st_atimespec
207#define st_ctim st_ctimespec
208#define st_mtim st_mtimespec
214 timestamp[0].tv_sec=attributes->st_atim.tv_sec;
215 timestamp[0].tv_nsec=attributes->st_atim.tv_nsec;
216 timestamp[1].tv_sec=attributes->st_mtim.tv_sec;
217 timestamp[1].tv_nsec=attributes->st_mtim.tv_nsec;
218 status=utimensat(AT_FDCWD,path,timestamp,0);
223 timestamp.actime=attributes->st_atime;
224 timestamp.modtime=attributes->st_mtime;
225 status=utime(path,×tamp);
228 status=NTSetFileTimestamp(path,attributes);
233static inline int stat_utf8(
const char *path,
struct stat *attributes)
235#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
236 return(stat(path,attributes));
238 return(NTStatWide(path,attributes));
242#if defined(__cplusplus) || defined(c_plusplus)