MagickCore 6.9.13
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
73#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
74typedef int
75 mode_t;
76#endif
77
78static inline int open_utf8(const char *path,int flags,mode_t mode)
79{
80#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
81 return(open(path,flags,mode));
82#else
83 return(NTOpenWide(path,flags,mode));
84#endif
85}
86
87static inline FILE *popen_utf8(const char *command,const char *type)
88{
89#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
90 return(popen(command,type));
91#else
92 return(NTOpenPipeWide(command,type));
93#endif
94}
95
96static inline char *realpath_utf8(const char *path)
97{
98#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
99#if defined(MAGICKCORE_HAVE_REALPATH)
100 /*
101 This does not work for non-existing files so we should fine another way
102 to do this in the future. This is only a possible issue when writing files.
103 */
104 return(realpath(path,(char *) NULL));
105#else
106 return(AcquireString(path));
107#endif
108#else
109 return(NTRealPathWide(path));
110#endif
111}
112
113static inline int remove_utf8(const char *path)
114{
115#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
116 return(unlink(path));
117#else
118 return(NTRemoveWide(path));
119#endif
120}
121
122static inline int rename_utf8(const char *source,const char *destination)
123{
124#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
125 return(rename(source,destination));
126#else
127 return(NTRenameWide(source,destination));
128#endif
129}
130
131static inline int set_file_timestamp(const char *path,struct stat *attributes)
132{
133 int
134 status;
135
136#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
137#if defined(MAGICKCORE_HAVE_UTIMENSAT)
138#if defined(__APPLE__) || defined(__NetBSD__)
139#define st_atim st_atimespec
140#define st_ctim st_ctimespec
141#define st_mtim st_mtimespec
142#endif
143
144 struct timespec
145 timestamp[2];
146
147 timestamp[0].tv_sec=attributes->st_atim.tv_sec;
148 timestamp[0].tv_nsec=attributes->st_atim.tv_nsec;
149 timestamp[1].tv_sec=attributes->st_mtim.tv_sec;
150 timestamp[1].tv_nsec=attributes->st_mtim.tv_nsec;
151 status=utimensat(AT_FDCWD,path,timestamp,0);
152#else
153 struct utimbuf
154 timestamp;
155
156 timestamp.actime=attributes->st_atime;
157 timestamp.modtime=attributes->st_mtime;
158 status=utime(path,&timestamp);
159#endif
160#else
161 status=NTSetFileTimestamp(path,attributes);
162#endif
163 return(status);
164}
165
166static inline int stat_utf8(const char *path,struct stat *attributes)
167{
168#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
169 return(stat(path,attributes));
170#else
171 return(NTStatWide(path,attributes));
172#endif
173}
174
175#if defined(__cplusplus) || defined(c_plusplus)
176}
177#endif
178
179#endif
Definition mac.h:54