ObjFW  Diff

Differences From Artifact [0713e735b4]:

To Artifact [b9fdcbe5c3]:


24
25
26
27
28
29
30

31


32
33
34
35
36
37
38
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40







+
-
+
+







# include <pwd.h>
# include <grp.h>
#endif

#import "OFFile.h"
#import "OFString.h"
#import "OFArray.h"
#ifdef OF_THREADS
#import "OFThread.h"
# import "OFThread.h"
#endif
#import "OFDate.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "macros.h"

#ifdef _WIN32
# import <windows.h>
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74







-
+







#define DEFAULT_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
#define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH

OFFile *of_stdin = nil;
OFFile *of_stdout = nil;
OFFile *of_stderr = nil;

#ifndef _WIN32
#if defined(OF_THREADS) && !defined(_WIN32)
static OFMutex *mutex;
#endif

static int parse_mode(const char *mode)
{
	if (!strcmp(mode, "r"))
		return O_RDONLY;
106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122







-
+







		return;

	of_stdin = [[OFFileSingleton alloc] initWithFileDescriptor: 0];
	of_stdout = [[OFFileSingleton alloc] initWithFileDescriptor: 1];
	of_stderr = [[OFFileSingleton alloc] initWithFileDescriptor: 2];
}

#ifndef _WIN32
#if defined(OF_THREADS) && !defined(_WIN32)
+ (void)initialize
{
	if (self == [OFFile class])
		mutex = [[OFMutex alloc] init];
}
#endif

416
417
418
419
420
421
422

423
424
425

426
427
428
429
430
431
432
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436







+



+







	uid_t uid = -1;
	gid_t gid = -1;

	if (owner == nil && group == nil)
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];

# ifdef OF_THREADS
	[mutex lock];

	@try {
# endif
		if (owner != nil) {
			struct passwd *pw;

			if ((pw = getpwnam([owner cString])) == NULL)
				@throw [OFChangeFileOwnerFailedException
				    newWithClass: self
					    path: path
444
445
446
447
448
449
450

451
452
453

454
455
456
457
458
459
460
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466







+



+







				    newWithClass: self
					    path: path
					   owner: owner
					   group: group];

			gid = gr->gr_gid;
		}
# ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
# endif

	if (chown([path cString], uid, gid))
		@throw [OFChangeFileOwnerFailedException newWithClass: self
								 path: path
								owner: owner
								group: group];
}