ObjFW  Diff

Differences From Artifact [9c9c1d09c4]:

To Artifact [ea32f092c7]:


186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218


219
220
221
222
223
224
225
226
227
228
229
230
231

232
233
234
235



236
237
238
239
240
241
242
243
244
245

246
247
248
249
250
251







252
253
254
255
256
257
258
259
260
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200


















201
202
203









204
205

206




207
208
209

210
211
212
213
214
215
216


217






218
219
220
221
222
223
224


225
226
227
228
229
230
231







-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
-
-
-
-
-
-
-
-


-
+
-
-
-
-
+
+
+
-







-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-







{
	if (close && fp != NULL)
		fclose(fp);

	[super dealloc];
}

- (BOOL)atEndOfStream
- (BOOL)atEndOfStreamWithoutCache
{
	if (fp == NULL)
		return YES;

	return (feof(fp) == 0 ? NO : YES);
}

- (size_t)readNItems: (size_t)nitems
	      ofSize: (size_t)size
	  intoBuffer: (char*)buf
{
	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
- (size_t)readNBytesWithoutCache: (size_t)size
		      intoBuffer: (char*)buf
{
	return [self readNItems: size
			 ofSize: 1
		     intoBuffer: buf];
}

- (size_t)writeNItems: (size_t)nitems
	       ofSize: (size_t)size
	   fromBuffer: (const char*)buf
{
	size_t ret;

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

	return ret;
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const char*)buf
{
	return [self writeNItems: size
			  ofSize: 1
	size_t ret;
		      fromBuffer: buf];
}

- (size_t)writeCString: (const char*)str
{
	return [self writeNItems: strlen(str)

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

	return ret;
			  ofSize: 1
		      fromBuffer: str];
}

- close
{
	fclose(fp);
	fp = NULL;