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