54
54
# include < sys/time.h>
55
55
# include < dirent.h>
56
56
# include < unistd.h>
57
- # if __has_include(<direct.h>)
57
+ # if __has_include(<direct.h>) || defined(LIBPLZMA_MINGW)
58
58
# include < direct.h>
59
59
# endif
60
+ # if __has_include(<io.h>) || defined(LIBPLZMA_MINGW)
61
+ # include < io.h>
62
+ # endif
60
63
#else
61
64
# error "Error once: file contains unimplemented functionality."
62
65
#endif
63
66
64
- #if defined(LIBPLZMA_OS_WINDOWS)
67
+ #if defined(LIBPLZMA_OS_WINDOWS) || defined(LIBPLZMA_MINGW)
65
68
# define CLZMA_SEP_WSTR L" \\ "
66
69
# define CLZMA_SEP_CSTR " \\ "
67
70
#elif defined(LIBPLZMA_POSIX)
@@ -77,7 +80,7 @@ namespace pathUtils {
77
80
78
81
template <>
79
82
inline bool pathExists (const wchar_t * LIBPLZMA_NONNULL path, bool * LIBPLZMA_NULLABLE isDir) noexcept {
80
- #if defined(LIBPLZMA_MSC)
83
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
81
84
if (::_waccess (path, 0 ) == 0 ) {
82
85
if (isDir) {
83
86
struct _stat statbuf;
@@ -100,7 +103,7 @@ namespace pathUtils {
100
103
101
104
template <>
102
105
inline bool pathExists (const char * LIBPLZMA_NONNULL path, bool * LIBPLZMA_NULLABLE isDir) noexcept {
103
- #if defined(LIBPLZMA_MSC)
106
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
104
107
if (::_access (path, 0 ) == 0 ) {
105
108
if (isDir) {
106
109
struct _stat statbuf;
@@ -137,7 +140,7 @@ namespace pathUtils {
137
140
template <>
138
141
inline plzma_path_stat pathStat (const wchar_t * LIBPLZMA_NULLABLE path) noexcept {
139
142
plzma_path_stat t{0 , {0 , 0 , 0 }};
140
- #if defined(LIBPLZMA_MSC)
143
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
141
144
if (path) {
142
145
struct __stat64 statbuf;
143
146
if (::_wstat64 (path, &statbuf) == 0 ) {
@@ -156,7 +159,7 @@ namespace pathUtils {
156
159
template <>
157
160
inline plzma_path_stat pathStat (const char * LIBPLZMA_NULLABLE path) noexcept {
158
161
plzma_path_stat t{0 , {0 , 0 , 0 }};
159
- #if defined(LIBPLZMA_MSC)
162
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
160
163
if (path) {
161
164
struct _stat statbuf;
162
165
if (::_stat (path, &statbuf) == 0 ) {
@@ -184,7 +187,7 @@ namespace pathUtils {
184
187
185
188
template <>
186
189
inline bool pathReadable (const wchar_t * LIBPLZMA_NONNULL path) noexcept {
187
- #if defined(LIBPLZMA_MSC)
190
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
188
191
return (::_waccess (path, 4 ) == 0 );
189
192
#else
190
193
assert (0 );
@@ -194,7 +197,7 @@ namespace pathUtils {
194
197
195
198
template <>
196
199
inline bool pathReadable (const char * LIBPLZMA_NONNULL path) noexcept {
197
- #if defined(LIBPLZMA_MSC)
200
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
198
201
return (::_access (path, 4 ) == 0 );
199
202
#elif defined(LIBPLZMA_POSIX)
200
203
return (::access (path, R_OK) == 0 );
@@ -206,7 +209,7 @@ namespace pathUtils {
206
209
207
210
template <>
208
211
inline bool pathWritable (const wchar_t * LIBPLZMA_NONNULL path) noexcept {
209
- #if defined(LIBPLZMA_MSC)
212
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
210
213
return (::_waccess (path, 2 ) == 0 );
211
214
#else
212
215
assert (0 );
@@ -216,7 +219,7 @@ namespace pathUtils {
216
219
217
220
template <>
218
221
inline bool pathWritable (const char * LIBPLZMA_NONNULL path) noexcept {
219
- #if defined(LIBPLZMA_MSC)
222
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
220
223
return (::_access (path, 2 ) == 0 );
221
224
#elif defined(LIBPLZMA_POSIX)
222
225
return (::access (path, W_OK) == 0 );
@@ -228,7 +231,7 @@ namespace pathUtils {
228
231
229
232
template <>
230
233
inline bool pathReadableAndWritable (const wchar_t * LIBPLZMA_NONNULL path) noexcept {
231
- #if defined(LIBPLZMA_MSC)
234
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
232
235
return (::_waccess (path, 6 ) == 0 );
233
236
#else
234
237
assert (0 );
@@ -238,7 +241,7 @@ namespace pathUtils {
238
241
239
242
template <>
240
243
inline bool pathReadableAndWritable (const char * LIBPLZMA_NONNULL path) noexcept {
241
- #if defined(LIBPLZMA_MSC)
244
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
242
245
return (::_access (path, 6 ) == 0 );
243
246
#elif defined(LIBPLZMA_POSIX)
244
247
return (::access (path, R_OK | W_OK) == 0 );
@@ -250,7 +253,7 @@ namespace pathUtils {
250
253
251
254
template <>
252
255
inline bool createSingleDir (const wchar_t * LIBPLZMA_NONNULL path) noexcept {
253
- #if defined(LIBPLZMA_MSC)
256
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
254
257
return (::_wmkdir (path) == 0 );
255
258
#else
256
259
assert (0 );
@@ -260,7 +263,7 @@ namespace pathUtils {
260
263
261
264
template <>
262
265
inline bool createSingleDir (const char * LIBPLZMA_NONNULL path) noexcept {
263
- #if defined(LIBPLZMA_MSC)
266
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
264
267
return (::_mkdir (path) == 0 );
265
268
#elif defined(LIBPLZMA_POSIX)
266
269
const mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR |
@@ -286,7 +289,7 @@ namespace pathUtils {
286
289
287
290
template <typename T>
288
291
constexpr T platformSeparator () noexcept {
289
- #if defined(LIBPLZMA_OS_WINDOWS)
292
+ #if defined(LIBPLZMA_OS_WINDOWS) || defined(LIBPLZMA_MINGW)
290
293
return (sizeof (T) > sizeof (char )) ? L' \\ ' : ' \\ ' ;
291
294
#elif defined(LIBPLZMA_POSIX)
292
295
return (sizeof (T) > sizeof (char )) ? L' /' : ' /' ;
@@ -295,7 +298,7 @@ namespace pathUtils {
295
298
296
299
template <typename T>
297
300
constexpr T additionalSeparator () noexcept {
298
- #if defined(LIBPLZMA_OS_WINDOWS)
301
+ #if defined(LIBPLZMA_OS_WINDOWS) || defined(LIBPLZMA_MINGW)
299
302
return (sizeof (T) > sizeof (char )) ? L' /' : ' /' ;
300
303
#elif defined(LIBPLZMA_POSIX)
301
304
return (sizeof (T) > sizeof (char )) ? L' \\ ' : ' \\ ' ;
@@ -353,7 +356,7 @@ namespace pathUtils {
353
356
354
357
template <>
355
358
inline bool removeEmptyDir (const wchar_t * LIBPLZMA_NONNULL path) noexcept {
356
- #if defined(LIBPLZMA_MSC)
359
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
357
360
return (::_wrmdir (path) == 0 );
358
361
#else
359
362
assert (0 );
@@ -363,9 +366,9 @@ namespace pathUtils {
363
366
364
367
template <>
365
368
inline bool removeEmptyDir (const char * LIBPLZMA_NONNULL path) noexcept {
366
- #if defined(LIBPLZMA_MSC)
369
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
367
370
return (::_rmdir (path) == 0 );
368
- #else
371
+ #elif defined(LIBPLZMA_POSIX)
369
372
return (::rmdir (path) == 0 );
370
373
#endif
371
374
}
@@ -375,7 +378,7 @@ namespace pathUtils {
375
378
376
379
template <>
377
380
inline bool removeFile (const wchar_t * LIBPLZMA_NONNULL path) noexcept {
378
- #if defined(LIBPLZMA_MSC)
381
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
379
382
return (::_wremove (path) == 0 );
380
383
#else
381
384
assert (0 );
@@ -545,20 +548,7 @@ namespace pathUtils {
545
548
return false ;
546
549
}
547
550
548
- #if defined(LIBPLZMA_MSC)
549
- struct RAIIFindHANDLE final {
550
- LIBPLZMA_NON_COPYABLE_NON_MOVABLE (RAIIFindHANDLE)
551
- HANDLE handle = INVALID_HANDLE_VALUE;
552
- RAIIFindHANDLE () = default ;
553
- ~RAIIFindHANDLE () {
554
- if (handle != INVALID_HANDLE_VALUE) {
555
- ::FindClose (handle);
556
- }
557
- }
558
- };
559
-
560
- LIBPLZMA_CPP_API_PRIVATE (bool ) removeDir(Path & path, const bool skipErrors);
561
- #elif defined(LIBPLZMA_POSIX)
551
+ #if defined(LIBPLZMA_POSIX)
562
552
struct RAIIDIR final {
563
553
LIBPLZMA_NON_COPYABLE_NON_MOVABLE (RAIIDIR)
564
554
DIR * LIBPLZMA_NULLABLE dir = nullptr ;
@@ -570,8 +560,22 @@ namespace pathUtils {
570
560
}
571
561
};
572
562
563
+ LIBPLZMA_CPP_API_PRIVATE (bool ) removeDir(Path & path, const bool skipErrors);
564
+ #elif defined(LIBPLZMA_MSC)
565
+ struct RAIIFindHANDLE final {
566
+ LIBPLZMA_NON_COPYABLE_NON_MOVABLE (RAIIFindHANDLE)
567
+ HANDLE handle = INVALID_HANDLE_VALUE;
568
+ RAIIFindHANDLE () = default ;
569
+ ~RAIIFindHANDLE () {
570
+ if (handle != INVALID_HANDLE_VALUE) {
571
+ ::FindClose (handle);
572
+ }
573
+ }
574
+ };
575
+
573
576
LIBPLZMA_CPP_API_PRIVATE (bool ) removeDir(Path & path, const bool skipErrors);
574
577
#endif
578
+
575
579
template <typename T>
576
580
bool removePath (const T * LIBPLZMA_NONNULL path, const bool skipErrors) {
577
581
bool isDir = false ;
@@ -592,7 +596,7 @@ namespace pathUtils {
592
596
593
597
template <>
594
598
inline bool setFileTimestamp (const wchar_t * LIBPLZMA_NONNULL path, const plzma_path_timestamp & timestamp) noexcept {
595
- #if defined(LIBPLZMA_MSC)
599
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
596
600
struct _utimbuf timeBuff{0 , 0 };
597
601
timeBuff.actime = timestamp.last_access ;
598
602
timeBuff.modtime = timestamp.last_modification ;
@@ -605,7 +609,7 @@ namespace pathUtils {
605
609
606
610
template <>
607
611
inline bool setFileTimestamp (const char * LIBPLZMA_NONNULL path, const plzma_path_timestamp & timestamp) noexcept {
608
- #if defined(LIBPLZMA_MSC)
612
+ #if defined(LIBPLZMA_MSC) || defined(LIBPLZMA_MINGW)
609
613
struct _utimbuf timeBuff{0 , 0 };
610
614
timeBuff.actime = timestamp.last_access ;
611
615
timeBuff.modtime = timestamp.last_modification ;
@@ -621,6 +625,4 @@ namespace pathUtils {
621
625
} // namespace plzma
622
626
} // namespace pathUtils
623
627
624
- // #include <CoreFoundation/CoreFoundation.h>
625
-
626
628
#endif // !__PLZMA_PATH_UTILS_HPP__
0 commit comments