ObjFW  Diff

Differences From Artifact [9a531e1b8b]:

To Artifact [4d9a49c8b5]:


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

static OFFileSingleton *of_file_stdin = nil;
static OFFileSingleton *of_file_stdout = nil;
static OFFileSingleton *of_file_stderr = nil;

@implementation OFFile
+ fileWithPath: (OFString*)path
       andMode: (OFString*)mode
{
	return [[[self alloc] initWithPath: path
				   andMode: mode] autorelease];
}

+ standardInput
{
	if (of_file_stdin == nil)
		of_file_stdin = [[OFFileSingleton alloc]
		    initWithFilePointer: stdin];







|


|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

static OFFileSingleton *of_file_stdin = nil;
static OFFileSingleton *of_file_stdout = nil;
static OFFileSingleton *of_file_stderr = nil;

@implementation OFFile
+ fileWithPath: (OFString*)path
	  mode: (OFString*)mode
{
	return [[[self alloc] initWithPath: path
				      mode: mode] autorelease];
}

+ standardInput
{
	if (of_file_stdin == nil)
		of_file_stdin = [[OFFileSingleton alloc]
		    initWithFilePointer: stdin];
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	 */
#ifndef _WIN32
	chmod([path cString], mode);
#endif
}

+ (void)changeOwnerOfFile: (OFString*)path
		  toOwner: (uid_t)owner
		 andGroup: (gid_t)group
{
	/* FIXME: On error, throw exception */
#ifndef _WIN32
	chown([path cString], owner, group);
#endif
}








|
|







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	 */
#ifndef _WIN32
	chmod([path cString], mode);
#endif
}

+ (void)changeOwnerOfFile: (OFString*)path
		    owner: (uid_t)owner
		    group: (gid_t)group
{
	/* FIXME: On error, throw exception */
#ifndef _WIN32
	chown([path cString], owner, group);
#endif
}

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
	/* FIXME: On error, throw exception */
#ifndef _WIN32
	symlink([src cString], [dest cString]);
#endif
}

- initWithPath: (OFString*)path
       andMode: (OFString*)mode
{
	Class c;

	self = [super init];

	if ((fp = fopen([path cString], [mode cString])) == NULL) {
		c = isa;
		[super dealloc];
		@throw [OFOpenFileFailedException newWithClass: c
						       andPath: path
						       andMode: mode];
	}

	return self;
}

- (void)dealloc
{







|









|
|







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
	/* FIXME: On error, throw exception */
#ifndef _WIN32
	symlink([src cString], [dest cString]);
#endif
}

- initWithPath: (OFString*)path
	  mode: (OFString*)mode
{
	Class c;

	self = [super init];

	if ((fp = fopen([path cString], [mode cString])) == NULL) {
		c = isa;
		[super dealloc];
		@throw [OFOpenFileFailedException newWithClass: c
							  path: path
							  mode: mode];
	}

	return self;
}

- (void)dealloc
{
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
{
	size_t ret;

	if (fp == NULL || feof(fp) ||
	    ((ret = fread(buf, size, nitems, fp)) == 0 &&
	    size != 0 && nitems != 0 && !feof(fp)))
		@throw [OFReadFailedException newWithClass: isa
						   andSize: size
						 andNItems: nitems];

	return ret;
}

- (size_t)readNBytes: (size_t)size
	  intoBuffer: (char*)buf
{







|
|







148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
{
	size_t ret;

	if (fp == NULL || feof(fp) ||
	    ((ret = fread(buf, size, nitems, fp)) == 0 &&
	    size != 0 && nitems != 0 && !feof(fp)))
		@throw [OFReadFailedException newWithClass: isa
						      size: size
						     items: nitems];

	return ret;
}

- (size_t)readNBytes: (size_t)size
	  intoBuffer: (char*)buf
{
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{
	size_t ret;

	if (fp == NULL || feof(fp) ||
	    ((ret = fwrite(buf, size, nitems, fp)) < nitems &&
	    size != 0 && nitems != 0))
		@throw [OFWriteFailedException newWithClass: isa
						    andSize: size
						  andNItems: nitems];

	return ret;
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const char*)buf
{







|
|







172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{
	size_t ret;

	if (fp == NULL || feof(fp) ||
	    ((ret = fwrite(buf, size, nitems, fp)) < nitems &&
	    size != 0 && nitems != 0))
		@throw [OFWriteFailedException newWithClass: isa
						       size: size
						      items: nitems];

	return ret;
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const char*)buf
{
234
235
236
237
238
239
240
241
242
243
244
{
	return SIZE_MAX;
}

- (void)dealloc
{
	@throw [OFNotImplementedException newWithClass: isa
					   andSelector: _cmd];
	[super dealloc];	/* Get rid of stupid warning */
}
@end







|



234
235
236
237
238
239
240
241
242
243
244
{
	return SIZE_MAX;
}

- (void)dealloc
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
	[super dealloc];	/* Get rid of stupid warning */
}
@end