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)
35extern MagickPrivate
char
36 **GetPathComponents(
const char *,
size_t *),
37 **ListFiles(
const char *,
const char *,
size_t *);
39extern MagickPrivate MagickBooleanType
40 GetExecutionPath(
char *,
const size_t),
41 ShredFile(
const char *);
43extern MagickPrivate ssize_t
44 GetMagickPageSize(
void);
46extern MagickPrivate
void
47 ChopPathComponents(
char *,
const size_t),
48 ExpandFilename(
char *);
50static inline int MagickReadDirectory(DIR *directory,
struct dirent *entry,
55 *result=readdir(directory);
59static inline int access_utf8(
const char *path,
int mode)
61 if (path == (
const char *) NULL)
63#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
64 return(access(path,mode));
66 return(NTAccessWide(path,mode));
70#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__)
71#define close_utf8 _close
73#define close_utf8 close
76static inline FILE *fopen_utf8(
const char *path,
const char *mode)
78#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
79 return(fopen(path,mode));
81 return(NTOpenFileWide(path,mode));
85static inline MagickBooleanType is_symlink_utf8(
const char *path)
87#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
88#if defined(MAGICKCORE_POSIX_SUPPORT)
92 if (lstat(path,&status) == -1)
94 return(S_ISLNK(status.st_mode) != 0 ? MagickTrue : MagickFalse);
99 return(NTIsSymlinkWide(path));
103static inline int open_utf8(
const char *path,
int flags,mode_t mode)
105#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
106 return(open(path,flags,mode));
108 return(NTOpenWide(path,flags,mode));
112static inline FILE *popen_utf8(
const char *command,
const char *type)
114#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
115 return(popen(command,type));
117 return(NTOpenPipeWide(command,type));
121static inline char *realpath_utf8(
const char *path)
123#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
124#if defined(MAGICKCORE_HAVE_REALPATH)
129 return(realpath(path,(
char *) NULL));
131 return(AcquireString(path));
134 return(NTRealPathWide(path));
138static inline int remove_utf8(
const char *path)
140#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
141 return(unlink(path));
143 return(NTRemoveWide(path));
147static inline int rename_utf8(
const char *source,
const char *destination)
149#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
150 return(rename(source,destination));
152 return(NTRenameWide(source,destination));
156static inline int set_file_timestamp(
const char *path,
struct stat *attributes)
161#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
162#if defined(MAGICKCORE_HAVE_UTIMENSAT)
163#if defined(__APPLE__) || defined(__NetBSD__)
164#define st_atim st_atimespec
165#define st_ctim st_ctimespec
166#define st_mtim st_mtimespec
172 timestamp[0].tv_sec=attributes->st_atim.tv_sec;
173 timestamp[0].tv_nsec=attributes->st_atim.tv_nsec;
174 timestamp[1].tv_sec=attributes->st_mtim.tv_sec;
175 timestamp[1].tv_nsec=attributes->st_mtim.tv_nsec;
176 status=utimensat(AT_FDCWD,path,timestamp,0);
181 timestamp.actime=attributes->st_atime;
182 timestamp.modtime=attributes->st_mtime;
183 status=utime(path,×tamp);
186 status=NTSetFileTimestamp(path,attributes);
191static inline int stat_utf8(
const char *path,
struct stat *attributes)
193#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
194 return(stat(path,attributes));
196 return(NTStatWide(path,attributes));
200#if defined(__cplusplus) || defined(c_plusplus)