ObjFW  Diff

Differences From Artifact [7e257a10c2]:

To Artifact [737527b063]:


53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67







-
+







#import "OFOpenItemFailedException.h"
#import "OFOutOfMemoryException.h"
#import "OFReadFailedException.h"
#import "OFRemoveItemFailedException.h"
#import "OFStatItemFailedException.h"
#import "OFUnlockFailedException.h"

#ifdef _WIN32
#ifdef OF_WINDOWS
# include <windows.h>
# include <direct.h>
#endif

#ifndef S_IRGRP
# define S_IRGRP 0
#endif
79
80
81
82
83
84
85
86

87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
79
80
81
82
83
84
85

86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114







-
+






-
+













-
+







#define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH

static OFFileManager *defaultManager;

#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
static of_mutex_t chownMutex;
#endif
#if !defined(HAVE_READDIR_R) && !defined(_WIN32) && defined(OF_HAVE_THREADS)
#if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS)
static of_mutex_t readdirMutex;
#endif

int
of_stat(OFString *path, of_stat_t *buffer)
{
#if defined(_WIN32)
#if defined(OF_WINDOWS)
	return _wstat64([path UTF16String], buffer);
#elif defined(OF_HAVE_OFF64_T)
	return stat64([path cStringWithEncoding:
	    [OFSystemInfo native8BitEncoding]], buffer);
#else
	return stat([path cStringWithEncoding:
	    [OFSystemInfo native8BitEncoding]], buffer);
#endif
}

int
of_lstat(OFString *path, of_stat_t *buffer)
{
#if defined(_WIN32)
#if defined(OF_WINDOWS)
	return _wstat64([path UTF16String], buffer);
#elif defined(HAVE_LSTAT)
# ifdef OF_HAVE_OFF64_T
	return lstat64([path cStringWithEncoding:
	    [OFSystemInfo native8BitEncoding]], buffer);
# else
	return lstat([path cStringWithEncoding:
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170

171
172
173
174
175
176
177
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169

170
171
172
173
174
175
176
177







-
+
















-
+






-
+








#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
	if (!of_mutex_new(&chownMutex))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
#endif

#if !defined(HAVE_READDIR_R) && !defined(_WIN32) && defined(OF_HAVE_THREADS)
#if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS)
	if (!of_mutex_new(&readdirMutex))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
#endif

	defaultManager = [[OFFileManager alloc] init];
}

+ (OFFileManager*)defaultManager
{
	return defaultManager;
}

- (OFString*)currentDirectoryPath
{
	OFString *ret;
#ifndef _WIN32
#ifndef OF_WINDOWS
	char *buffer = getcwd(NULL, 0);
#else
	wchar_t *buffer = _wgetcwd(NULL, 0);
#endif

	@try {
#ifndef _WIN32
#ifndef OF_WINDOWS
		ret = [OFString
		    stringWithCString: buffer
			     encoding: [OFSystemInfo native8BitEncoding]];
#else
		ret = [OFString stringWithUTF16String: buffer];
#endif
	} @finally {
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246







-
+







#endif

- (void)createDirectoryAtPath: (OFString*)path
{
	if (path == nil)
		@throw [OFInvalidArgumentException exception];

#ifndef _WIN32
#ifndef OF_WINDOWS
	if (mkdir([path cStringWithEncoding: [OFSystemInfo native8BitEncoding]],
	    DIR_MODE) != 0)
#else
	if (_wmkdir([path UTF16String]) != 0)
#endif
		@throw [OFCreateDirectoryFailedException
		    exceptionWithPath: path
289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
304
305

306
307
308
309
310
311
312
289
290
291
292
293
294
295

296
297
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312







-
+








-
+








	objc_autoreleasePoolPop(pool);
}

- (OFArray*)contentsOfDirectoryAtPath: (OFString*)path
{
	OFMutableArray *files;
#ifndef _WIN32
#ifndef OF_WINDOWS
	of_string_encoding_t encoding;
#endif

	if (path == nil)
		@throw [OFInvalidArgumentException exception];

	files = [OFMutableArray array];

#ifndef _WIN32
#ifndef OF_WINDOWS
	DIR *dir;

	encoding = [OFSystemInfo native8BitEncoding];

	if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL)
		@throw [OFOpenItemFailedException exceptionWithPath: path
							      errNo: errno];
414
415
416
417
418
419
420
421

422
423
424
425
426
427
428
414
415
416
417
418
419
420

421
422
423
424
425
426
427
428







-
+







}

- (void)changeCurrentDirectoryPath: (OFString*)path
{
	if (path == nil)
		@throw [OFInvalidArgumentException exception];

#ifndef _WIN32
#ifndef OF_WINDOWS
	if (chdir([path cStringWithEncoding:
	    [OFSystemInfo native8BitEncoding]]) != 0)
#else
	if (_wchdir([path UTF16String]) != 0)
#endif
		@throw [OFChangeCurrentDirectoryPathFailedException
		    exceptionWithPath: path
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
491
492
493
494
495
496
497

498
499
500
501
502
503
504
505







-
+







#ifdef OF_HAVE_CHMOD
- (void)changePermissionsOfItemAtPath: (OFString*)path
			  permissions: (mode_t)permissions
{
	if (path == nil)
		@throw [OFInvalidArgumentException exception];

# ifndef _WIN32
# ifndef OF_WINDOWS
	if (chmod([path cStringWithEncoding: [OFSystemInfo native8BitEncoding]],
	    permissions) != 0)
# else
	if (_wchmod([path UTF16String], permissions) != 0)
# endif
		@throw [OFChangePermissionsFailedException
		    exceptionWithPath: path
718
719
720
721
722
723
724
725

726
727
728
729
730
731
732
733
734
735
736
737
738
739
740

741
742
743
744
745
746
747
718
719
720
721
722
723
724

725
726
727
728
729
730
731
732
733
734
735
736
737
738
739

740
741
742
743
744
745
746
747







-
+














-
+







}

- (void)moveItemAtPath: (OFString*)source
		toPath: (OFString*)destination
{
	void *pool;
	of_stat_t s;
#ifndef _WIN32
#ifndef OF_WINDOWS
	of_string_encoding_t encoding;
#endif

	if (source == nil || destination == nil)
		@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();

	if (of_lstat(destination, &s) == 0)
		@throw [OFCopyItemFailedException
		    exceptionWithSourcePath: source
			    destinationPath: destination
				      errNo: EEXIST];

#ifndef _WIN32
#ifndef OF_WINDOWS
	encoding = [OFSystemInfo native8BitEncoding];

	if (rename([source cStringWithEncoding: encoding],
	    [destination cStringWithEncoding: encoding]) != 0) {
#else
	if (_wrename([source UTF16String], [destination UTF16String]) != 0) {
#endif
820
821
822
823
824
825
826
827

828
829
830
831
832
833
834
820
821
822
823
824
825
826

827
828
829
830
831
832
833
834







-
+







			[self removeItemAtPath:
			    [path stringByAppendingPathComponent: item]];

			objc_autoreleasePoolPop(pool2);
		}
	}

#ifndef _WIN32
#ifndef OF_WINDOWS
	if (remove([path cStringWithEncoding:
	    [OFSystemInfo native8BitEncoding]]) != 0)
#else
	if (_wremove([path UTF16String]) != 0)
#endif
		@throw [OFRemoveItemFailedException exceptionWithPath: path
								errNo: errno];