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 MagickReadDirectory(DIR *directory,
struct dirent *entry,
53 struct dirent **result)
57 *result=readdir(directory);
61static inline int access_utf8(
const char *path,
int mode)
63 if (path == (
const char *) NULL)
65#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
66 return(access(path,mode));
68 return(NTAccessWide(path,mode));
72#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__)
73#define close_utf8 _close
75#define close_utf8 close
78static inline FILE *fopen_utf8(
const char *path,
const char *mode)
80#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
81 return(fopen(path,mode));
83 return(NTOpenFileWide(path,mode));
87static inline MagickBooleanType is_symlink_utf8(
const char *path)
89#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
90#if defined(MAGICKCORE_POSIX_SUPPORT)
94 if (lstat(path,&status) == -1)
96 return(S_ISLNK(status.st_mode) != 0 ? MagickTrue : MagickFalse);
101 return(NTIsSymlinkWide(path));
105static inline int open_utf8(
const char *path,
int flags,mode_t mode)
107#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
108 return(open(path,flags,mode));
110 return(NTOpenWide(path,flags,mode));
114static inline FILE *popen_utf8(
const char *command,
const char *type)
116#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
117 return(popen(command,type));
119 return(NTOpenPipeWide(command,type));
123static inline char *realpath_utf8(
const char *path)
125#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
126#if defined(MAGICKCORE_HAVE_REALPATH)
131 return(realpath(path,(
char *) NULL));
133 return(AcquireString(path));
136 return(NTRealPathWide(path));
140static inline int remove_utf8(
const char *path)
142#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
143 return(unlink(path));
145 return(NTRemoveWide(path));
149static inline int rename_utf8(
const char *source,
const char *destination)
151#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
152 return(rename(source,destination));
154 return(NTRenameWide(source,destination));
158static inline int set_file_timestamp(
const char *path,
struct stat *attributes)
163#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
164#if defined(MAGICKCORE_HAVE_UTIMENSAT)
165#if defined(__APPLE__) || defined(__NetBSD__)
166#define st_atim st_atimespec
167#define st_ctim st_ctimespec
168#define st_mtim st_mtimespec
174 timestamp[0].tv_sec=attributes->st_atim.tv_sec;
175 timestamp[0].tv_nsec=attributes->st_atim.tv_nsec;
176 timestamp[1].tv_sec=attributes->st_mtim.tv_sec;
177 timestamp[1].tv_nsec=attributes->st_mtim.tv_nsec;
178 status=utimensat(AT_FDCWD,path,timestamp,0);
183 timestamp.actime=attributes->st_atime;
184 timestamp.modtime=attributes->st_mtime;
185 status=utime(path,×tamp);
188 status=NTSetFileTimestamp(path,attributes);
193static inline int stat_utf8(
const char *path,
struct stat *attributes)
195#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
196 return(stat(path,attributes));
198 return(NTStatWide(path,attributes));
202#if defined(__cplusplus) || defined(c_plusplus)