MagickCore 7.1.2-28
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 "MagickCore/memory_.h"
22#include "MagickCore/nt-base.h"
23#include "MagickCore/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 char
38 **GetPathComponents(const char *,size_t *),
39 **ListFiles(const char *,const char *,size_t *);
40
41extern MagickPrivate MagickBooleanType
42 GetExecutionPath(char *,const size_t),
43 ShredFile(const char *);
44
45extern MagickPrivate ssize_t
46 GetMagickPageSize(void);
47
48extern MagickPrivate void
49 ChopPathComponents(char *,const size_t),
50 ExpandFilename(char *);
51
52static inline int MagickReadDirectory(DIR *directory,struct dirent *entry,
53 struct dirent **result)
54{
55 (void) entry;
56 errno=0;
57 *result=readdir(directory);
58 return(errno);
59}
60
61static inline int access_utf8(const char *path,int mode)
62{
63 if (path == (const char *) NULL)
64 return(-1);
65#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
66 return(access(path,mode));
67#else
68 return(NTAccessWide(path,mode));
69#endif
70}
71
72#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__)
73#define close_utf8 _close
74#else
75#define close_utf8 close
76#endif
77
78static inline FILE *fopen_utf8(const char *path,const char *mode)
79{
80#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
81 return(fopen(path,mode));
82#else
83 return(NTOpenFileWide(path,mode));
84#endif
85}
86
87static inline MagickBooleanType is_symlink_utf8(const char *path)
88{
89#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
90#if defined(MAGICKCORE_POSIX_SUPPORT)
91 struct stat
92 status;
93
94 if (lstat(path,&status) == -1)
95 return(MagickFalse);
96 return(S_ISLNK(status.st_mode) != 0 ? MagickTrue : MagickFalse);
97#else
98 return(MagickFalse);
99#endif
100#else
101 return(NTIsSymlinkWide(path));
102#endif
103}
104
105static inline int open_utf8(const char *path,int flags,mode_t mode)
106{
107#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
108 return(open(path,flags,mode));
109#else
110 return(NTOpenWide(path,flags,mode));
111#endif
112}
113
114static inline FILE *popen_utf8(const char *command,const char *type)
115{
116#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
117 return(popen(command,type));
118#else
119 return(NTOpenPipeWide(command,type));
120#endif
121}
122
123static inline char *realpath_utf8(const char *path)
124{
125#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
126#if defined(MAGICKCORE_HAVE_REALPATH)
127 /*
128 This does not work for non-existing files so we should fine another way
129 to do this in the future. This is only a possible issue when writing files.
130 */
131 return(realpath(path,(char *) NULL));
132#else
133 return(AcquireString(path));
134#endif
135#else
136 return(NTRealPathWide(path));
137#endif
138}
139
140static inline int remove_utf8(const char *path)
141{
142#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
143 return(unlink(path));
144#else
145 return(NTRemoveWide(path));
146#endif
147}
148
149static inline int rename_utf8(const char *source,const char *destination)
150{
151#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
152 return(rename(source,destination));
153#else
154 return(NTRenameWide(source,destination));
155#endif
156}
157
158static inline int set_file_timestamp(const char *path,struct stat *attributes)
159{
160 int
161 status;
162
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
169#endif
170
171 struct timespec
172 timestamp[2];
173
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);
179#else
180 struct utimbuf
181 timestamp;
182
183 timestamp.actime=attributes->st_atime;
184 timestamp.modtime=attributes->st_mtime;
185 status=utime(path,&timestamp);
186#endif
187#else
188 status=NTSetFileTimestamp(path,attributes);
189#endif
190 return(status);
191}
192
193static inline int stat_utf8(const char *path,struct stat *attributes)
194{
195#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
196 return(stat(path,attributes));
197#else
198 return(NTStatWide(path,attributes));
199#endif
200}
201
202#if defined(__cplusplus) || defined(c_plusplus)
203}
204#endif
205
206#endif