MagickCore 6.9.13-53
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
utility-private.h
1/*
2 Copyright 1999 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
4
5 You may not use this file except in compliance with the License. You may
6 obtain a copy of the License at
7
8 https://imagemagick.org/license/
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 MagickCore private utility methods.
17*/
18#ifndef MAGICKCORE_UTILITY_PRIVATE_H
19#define MAGICKCORE_UTILITY_PRIVATE_H
20
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)
25#include <utime.h>
26#endif
27#if defined(__MINGW32__)
28#include <share.h>
29#endif
30
31#if defined(__cplusplus) || defined(c_plusplus)
32extern "C" {
33#endif
34
35#define MagickPathTemplate "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" /* min 6 X's */
36
37extern MagickPrivate MagickBooleanType
38 ShredFile(const char *);
39
40static inline int MagickReadDirectory(DIR *directory,struct dirent *entry,
41 struct dirent **result)
42{
43 (void) entry;
44 errno=0;
45 *result=readdir(directory);
46 return(errno);
47}
48
49static inline int access_utf8(const char *path,int mode)
50{
51 if (path == (const char *) NULL)
52 return(-1);
53#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
54 return(access(path,mode));
55#else
56 return(NTAccessWide(path,mode));
57#endif
58}
59
60#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__)
61#define close_utf8 _close
62#else
63#define close_utf8 close
64#endif
65
66static inline FILE *fopen_utf8(const char *path,const char *mode)
67{
68#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
69 return(fopen(path,mode));
70#else
71 return(NTOpenFileWide(path,mode));
72#endif
73}
74
75static inline MagickBooleanType is_symlink_utf8(const char *path)
76{
77#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
78#if defined(MAGICKCORE_POSIX_SUPPORT)
79 struct stat
80 status;
81
82 if (lstat(path,&status) == -1)
83 return(MagickFalse);
84 return(S_ISLNK(status.st_mode) != 0 ? MagickTrue : MagickFalse);
85#else
86 return(MagickFalse);
87#endif
88#else
89 return(NTIsSymlinkWide(path));
90#endif
91}
92
93#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
94typedef int
95 mode_t;
96#endif
97
98static inline int open_utf8(const char *path,int flags,mode_t mode)
99{
100#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
101 return(open(path,flags,mode));
102#else
103 return(NTOpenWide(path,flags,mode));
104#endif
105}
106
107static inline FILE *popen_utf8(const char *command,const char *type)
108{
109#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
110 return(popen(command,type));
111#else
112 return(NTOpenPipeWide(command,type));
113#endif
114}
115
116static inline char *realpath_utf8(const char *path)
117{
118#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
119#if defined(MAGICKCORE_HAVE_REALPATH)
120 /*
121 This does not work for non-existing files so we should fine another way
122 to do this in the future. This is only a possible issue when writing files.
123 */
124 return(realpath(path,(char *) NULL));
125#else
126 return(AcquireString(path));
127#endif
128#else
129 return(NTRealPathWide(path));
130#endif
131}
132
133static inline int remove_utf8(const char *path)
134{
135#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
136 return(unlink(path));
137#else
138 return(NTRemoveWide(path));
139#endif
140}
141
142static inline int rename_utf8(const char *source,const char *destination)
143{
144#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
145 return(rename(source,destination));
146#else
147 return(NTRenameWide(source,destination));
148#endif
149}
150
151static inline int set_file_timestamp(const char *path,struct stat *attributes)
152{
153 int
154 status;
155
156#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
157#if defined(MAGICKCORE_HAVE_UTIMENSAT)
158#if defined(__APPLE__) || defined(__NetBSD__)
159#define st_atim st_atimespec
160#define st_ctim st_ctimespec
161#define st_mtim st_mtimespec
162#endif
163
164 struct timespec
165 timestamp[2];
166
167 timestamp[0].tv_sec=attributes->st_atim.tv_sec;
168 timestamp[0].tv_nsec=attributes->st_atim.tv_nsec;
169 timestamp[1].tv_sec=attributes->st_mtim.tv_sec;
170 timestamp[1].tv_nsec=attributes->st_mtim.tv_nsec;
171 status=utimensat(AT_FDCWD,path,timestamp,0);
172#else
173 struct utimbuf
174 timestamp;
175
176 timestamp.actime=attributes->st_atime;
177 timestamp.modtime=attributes->st_mtime;
178 status=utime(path,&timestamp);
179#endif
180#else
181 status=NTSetFileTimestamp(path,attributes);
182#endif
183 return(status);
184}
185
186static inline int stat_utf8(const char *path,struct stat *attributes)
187{
188#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
189 return(stat(path,attributes));
190#else
191 return(NTStatWide(path,attributes));
192#endif
193}
194
195#if defined(__cplusplus) || defined(c_plusplus)
196}
197#endif
198
199#endif
Definition mac.h:54