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)
35extern MagickPrivate MagickBooleanType
36 ShredFile(
const char *);
38static inline int MagickReadDirectory(DIR *directory,
struct dirent *entry,
43 *result=readdir(directory);
47static inline int access_utf8(
const char *path,
int mode)
49 if (path == (
const char *) NULL)
51#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
52 return(access(path,mode));
54 return(NTAccessWide(path,mode));
58#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__)
59#define close_utf8 _close
61#define close_utf8 close
64static inline FILE *fopen_utf8(
const char *path,
const char *mode)
66#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
67 return(fopen(path,mode));
69 return(NTOpenFileWide(path,mode));
73#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
78static inline int open_utf8(
const char *path,
int flags,mode_t mode)
80#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
81 return(open(path,flags,mode));
83 return(NTOpenWide(path,flags,mode));
87static inline FILE *popen_utf8(
const char *command,
const char *type)
89#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
90 return(popen(command,type));
92 return(NTOpenPipeWide(command,type));
96static inline char *realpath_utf8(
const char *path)
98#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
99#if defined(MAGICKCORE_HAVE_REALPATH)
104 return(realpath(path,(
char *) NULL));
106 return(AcquireString(path));
109 return(NTRealPathWide(path));
113static inline int remove_utf8(
const char *path)
115#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
116 return(unlink(path));
118 return(NTRemoveWide(path));
122static inline int rename_utf8(
const char *source,
const char *destination)
124#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
125 return(rename(source,destination));
127 return(NTRenameWide(source,destination));
131static inline int set_file_timestamp(
const char *path,
struct stat *attributes)
136#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
137#if defined(MAGICKCORE_HAVE_UTIMENSAT)
138#if defined(__APPLE__) || defined(__NetBSD__)
139#define st_atim st_atimespec
140#define st_ctim st_ctimespec
141#define st_mtim st_mtimespec
147 timestamp[0].tv_sec=attributes->st_atim.tv_sec;
148 timestamp[0].tv_nsec=attributes->st_atim.tv_nsec;
149 timestamp[1].tv_sec=attributes->st_mtim.tv_sec;
150 timestamp[1].tv_nsec=attributes->st_mtim.tv_nsec;
151 status=utimensat(AT_FDCWD,path,timestamp,0);
156 timestamp.actime=attributes->st_atime;
157 timestamp.modtime=attributes->st_mtime;
158 status=utime(path,×tamp);
161 status=NTSetFileTimestamp(path,attributes);
166static inline int stat_utf8(
const char *path,
struct stat *attributes)
168#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
169 return(stat(path,attributes));
171 return(NTStatWide(path,attributes));
175#if defined(__cplusplus) || defined(c_plusplus)