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 int open_utf8(
const char *path,
int flags,mode_t mode)
87#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
88 return(open(path,flags,mode));
90 return(NTOpenWide(path,flags,mode));
94static inline FILE *popen_utf8(
const char *command,
const char *type)
96#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
97 return(popen(command,type));
99 return(NTOpenPipeWide(command,type));
103static inline char *realpath_utf8(
const char *path)
105#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
106#if defined(MAGICKCORE_HAVE_REALPATH)
111 return(realpath(path,(
char *) NULL));
113 return(AcquireString(path));
116 return(NTRealPathWide(path));
120static inline int remove_utf8(
const char *path)
122#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
123 return(unlink(path));
125 return(NTRemoveWide(path));
129static inline int rename_utf8(
const char *source,
const char *destination)
131#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
132 return(rename(source,destination));
134 return(NTRenameWide(source,destination));
138static inline int set_file_timestamp(
const char *path,
struct stat *attributes)
143#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
144#if defined(MAGICKCORE_HAVE_UTIMENSAT)
145#if defined(__APPLE__) || defined(__NetBSD__)
146#define st_atim st_atimespec
147#define st_ctim st_ctimespec
148#define st_mtim st_mtimespec
154 timestamp[0].tv_sec=attributes->st_atim.tv_sec;
155 timestamp[0].tv_nsec=attributes->st_atim.tv_nsec;
156 timestamp[1].tv_sec=attributes->st_mtim.tv_sec;
157 timestamp[1].tv_nsec=attributes->st_mtim.tv_nsec;
158 status=utimensat(AT_FDCWD,path,timestamp,0);
163 timestamp.actime=attributes->st_atime;
164 timestamp.modtime=attributes->st_mtime;
165 status=utime(path,×tamp);
168 status=NTSetFileTimestamp(path,attributes);
173static inline int stat_utf8(
const char *path,
struct stat *attributes)
175#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
176 return(stat(path,attributes));
178 return(NTStatWide(path,attributes));
182#if defined(__cplusplus) || defined(c_plusplus)