20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
|
#include <sys/stat.h>
#endif
#import "OFFile.h"
#import "OFExceptions.h"
@implementation OFFile
+ fileWithPath: (const char*)path
andMode: (const char*)mode
+ fileWithPath: (OFString*)path
andMode: (OFString*)mode
{
return [[[OFFile alloc] initWithPath: path
andMode: mode] autorelease];
}
+ (void)changeModeOfFile: (const char*)path
+ (void)changeModeOfFile: (OFString*)path
toMode: (mode_t)mode
{
/*
* FIXME: On error, throw exception
* FIXME: On Win32, change write access
*/
#ifndef _WIN32
chmod(path, mode);
chmod([path cString], mode);
#endif
}
+ (void)changeOwnerOfFile: (const char*)path
+ (void)changeOwnerOfFile: (OFString*)path
toOwner: (uid_t)owner
andGroup: (gid_t)group
{
/* FIXME: On error, throw exception */
#ifndef _WIN32
chown(path, owner, group);
chown([path cString], owner, group);
#endif
}
+ (void)delete: (const char*)path
+ (void)delete: (OFString*)path
{
/* FIXME: On error, throw exception */
unlink(path);
unlink([path cString]);
}
+ (void)link: (const char*)src
to: (const char*)dest
+ (void)link: (OFString*)src
to: (OFString*)dest
{
/* FIXME: On error, throw exception */
#ifndef _WIN32
link(src, dest);
link([src cString], [dest cString]);
#endif
}
+ (void)symlink: (const char*)src
to: (const char*)dest
+ (void)symlink: (OFString*)src
to: (OFString*)dest
{
/* FIXME: On error, throw exception */
#ifndef _WIN32
symlink(src, dest);
symlink([src cString], [dest cString]);
#endif
}
- initWithPath: (const char*)path
andMode: (const char*)mode
- initWithPath: (OFString*)path
andMode: (OFString*)mode
{
Class c;
self = [super init];
if ((fp = fopen(path, mode)) == NULL) {
if ((fp = fopen([path cString], [mode cString])) == NULL) {
c = isa;
[super dealloc];
@throw [OFOpenFileFailedException newWithClass: c
andPath: path
andMode: mode];
}
|