18#ifndef MAGICKCORE_UTILITY_PRIVATE_H
19#define MAGICKCORE_UTILITY_PRIVATE_H
21#include "magick/memory_.h"
22#include "magick/nt-base.h"
23#include "magick/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 MagickBooleanType
38 ShredFile(
const char *);
40static inline int MagickReadDirectory(DIR *directory,
struct dirent *entry,
45 *result=readdir(directory);
49static inline int access_utf8(
const char *path,
int mode)
51 if (path == (
const char *) NULL)
53#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
54 return(access(path,mode));
56 return(NTAccessWide(path,mode));
60#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__)
61#define close_utf8 _close
63#define close_utf8 close
66static inline FILE *fopen_utf8(
const char *path,
const char *mode)
68#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
69 return(fopen(path,mode));
71 return(NTOpenFileWide(path,mode));
75static inline MagickBooleanType is_symlink_utf8(
const char *path)
77#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
78#if defined(MAGICKCORE_POSIX_SUPPORT)
82 if (lstat(path,&status) == -1)
84 return(S_ISLNK(status.st_mode) != 0 ? MagickTrue : MagickFalse);
89 return(NTIsSymlinkWide(path));
93#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
98static inline int open_utf8(
const char *path,
int flags,mode_t mode)
100#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
101 return(open(path,flags,mode));
103 return(NTOpenWide(path,flags,mode));
107static inline FILE *popen_utf8(
const char *command,
const char *type)
109#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
110 return(popen(command,type));
112 return(NTOpenPipeWide(command,type));
116static inline char *realpath_utf8(
const char *path)
118#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
119#if defined(MAGICKCORE_HAVE_REALPATH)
124 return(realpath(path,(
char *) NULL));
126 return(AcquireString(path));
129 return(NTRealPathWide(path));
133static inline int remove_utf8(
const char *path)
135#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
136 return(unlink(path));
138 return(NTRemoveWide(path));
142static inline int rename_utf8(
const char *source,
const char *destination)
144#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
145 return(rename(source,destination));
147 return(NTRenameWide(source,destination));
151static inline int set_file_timestamp(
const char *path,
struct stat *attributes)
156#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
157#if defined(MAGICKCORE_HAVE_UTIMENSAT)
158#if defined(__APPLE__) || defined(__NetBSD__)
159#define st_atim st_atimespec
160#define st_ctim st_ctimespec
161#define st_mtim st_mtimespec
167 timestamp[0].tv_sec=attributes->st_atim.tv_sec;
168 timestamp[0].tv_nsec=attributes->st_atim.tv_nsec;
169 timestamp[1].tv_sec=attributes->st_mtim.tv_sec;
170 timestamp[1].tv_nsec=attributes->st_mtim.tv_nsec;
171 status=utimensat(AT_FDCWD,path,timestamp,0);
176 timestamp.actime=attributes->st_atime;
177 timestamp.modtime=attributes->st_mtime;
178 status=utime(path,×tamp);
181 status=NTSetFileTimestamp(path,attributes);
186static inline int stat_utf8(
const char *path,
struct stat *attributes)
188#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
189 return(stat(path,attributes));
191 return(NTStatWide(path,attributes));
195#if defined(__cplusplus) || defined(c_plusplus)