MagickCore 7.1.2
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 int open_utf8(const char *path,int flags,mode_t mode)
86{
87#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
88 return(open(path,flags,mode));
89#else
90 return(NTOpenWide(path,flags,mode));
91#endif
92}
93
94static inline FILE *popen_utf8(const char *command,const char *type)
95{
96#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
97 return(popen(command,type));
98#else
99 return(NTOpenPipeWide(command,type));
100#endif
101}
102
103static inline char *realpath_utf8(const char *path)
104{
105#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
106#if defined(MAGICKCORE_HAVE_REALPATH)
107 /*
108 This does not work for non-existing files so we should fine another way
109 to do this in the future. This is only a possible issue when writing files.
110 */
111 return(realpath(path,(char *) NULL));
112#else
113 return(AcquireString(path));
114#endif
115#else
116 return(NTRealPathWide(path));
117#endif
118}
119
120static inline int remove_utf8(const char *path)
121{
122#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
123 return(unlink(path));
124#else
125 return(NTRemoveWide(path));
126#endif
127}
128
129static inline int rename_utf8(const char *source,const char *destination)
130{
131#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
132 return(rename(source,destination));
133#else
134 return(NTRenameWide(source,destination));
135#endif
136}
137
138static inline int set_file_timestamp(const char *path,struct stat *attributes)
139{
140 int
141 status;
142
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
149#endif
150
151 struct timespec
152 timestamp[2];
153
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);
159#else
160 struct utimbuf
161 timestamp;
162
163 timestamp.actime=attributes->st_atime;
164 timestamp.modtime=attributes->st_mtime;
165 status=utime(path,&timestamp);
166#endif
167#else
168 status=NTSetFileTimestamp(path,attributes);
169#endif
170 return(status);
171}
172
173static inline int stat_utf8(const char *path,struct stat *attributes)
174{
175#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
176 return(stat(path,attributes));
177#else
178 return(NTStatWide(path,attributes));
179#endif
180}
181
182#if defined(__cplusplus) || defined(c_plusplus)
183}
184#endif
185
186#endif
Definition vms.h:942