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));
58static inline FILE *fopen_utf8(
const char *path,
const char *mode)
60#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
61 return(fopen(path,mode));
63 return(NTOpenFileWide(path,mode));
67#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
72static inline int open_utf8(
const char *path,
int flags,mode_t mode)
74#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
75 return(open(path,flags,mode));
77 return(NTOpenWide(path,flags,mode));
81static inline FILE *popen_utf8(
const char *command,
const char *type)
83#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
84 return(popen(command,type));
86 return(NTOpenPipeWide(command,type));
90static inline char *realpath_utf8(
const char *path)
92#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
93#if defined(MAGICKCORE_HAVE_REALPATH)
98 return(realpath(path,(
char *) NULL));
100 return(AcquireString(path));
103 return(NTRealPathWide(path));
107static inline int remove_utf8(
const char *path)
109#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
110 return(unlink(path));
112 return(NTRemoveWide(path));
116static inline int rename_utf8(
const char *source,
const char *destination)
118#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
119 return(rename(source,destination));
121 return(NTRenameWide(source,destination));
125static inline int set_file_timestamp(
const char *path,
struct stat *attributes)
130#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
131#if defined(MAGICKCORE_HAVE_UTIMENSAT)
132#if defined(__APPLE__) || defined(__NetBSD__)
133#define st_atim st_atimespec
134#define st_ctim st_ctimespec
135#define st_mtim st_mtimespec
141 timestamp[0].tv_sec=attributes->st_atim.tv_sec;
142 timestamp[0].tv_nsec=attributes->st_atim.tv_nsec;
143 timestamp[1].tv_sec=attributes->st_mtim.tv_sec;
144 timestamp[1].tv_nsec=attributes->st_mtim.tv_nsec;
145 status=utimensat(AT_FDCWD,path,timestamp,0);
150 timestamp.actime=attributes->st_atime;
151 timestamp.modtime=attributes->st_mtime;
152 status=utime(path,×tamp);
155 status=NTSetFileTimestamp(path,attributes);
160static inline int stat_utf8(
const char *path,
struct stat *attributes)
162#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
163 return(stat(path,attributes));
165 return(NTStatWide(path,attributes));
169#if defined(__cplusplus) || defined(c_plusplus)