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