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