ObjFW  Diff

Differences From Artifact [3b625f7cf5]:

To Artifact [c9c58ea96b]:


20
21
22
23
24
25
26




27
28
29
30
31
32
33
34
35
36








37
38
39
40
41
42
43
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







+
+
+
+










+
+
+
+
+
+
+
+







#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <assert.h>
#include <fcntl.h>

#ifndef _WIN32
# include <signal.h>
#endif

#import "OFStream.h"
#import "OFString.h"
#import "OFDataArray.h"
#import "OFExceptions.h"
#import "macros.h"

#import "asprintf.h"

@implementation OFStream
#ifndef _WIN32
+ (void)initialize
{
	if (self == [OFStream class])
		signal(SIGPIPE, SIG_IGN);
}
#endif

- init
{
	if (isa == [OFStream class]) {
		Class c = isa;
		[self release];
		@throw [OFNotImplementedException newWithClass: c
						      selector: _cmd];
238
239
240
241
242
243
244
245

246
247
248
249
250
251
252
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264







-
+







}

- (OFString*)readLine
{
	return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8];
}

- (OFString*)readLineWithEncoding: (enum of_string_encoding)encoding
- (OFString*)readLineWithEncoding: (of_string_encoding_t)encoding
{
	size_t i, len, ret_len;
	char *ret_c, *tmp, *tmp2;
	OFString *ret;

	/* Look if there's a line or \0 in our cache */
	if (cache != NULL) {
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412







-
+







- (OFString*)readTillDelimiter: (OFString*)delimiter
{
	return [self readTillDelimiter: delimiter
			  withEncoding: OF_STRING_ENCODING_UTF_8];
}

- (OFString*)readTillDelimiter: (OFString*)delimiter
		  withEncoding: (enum of_string_encoding)encoding
		  withEncoding: (of_string_encoding_t)encoding
{
	const char *delim;
	size_t i, j, delim_len, len, ret_len;
	char *ret_c, *tmp, *tmp2;
	OFString *ret;

	/* FIXME: Convert delimiter to specified charset */
628
629
630
631
632
633
634


635
636






637
638





639
640
641
642
643
644
645
640
641
642
643
644
645
646
647
648


649
650
651
652
653
654
655

656
657
658
659
660
661
662
663
664
665
666
667







+
+
-
-
+
+
+
+
+
+

-
+
+
+
+
+







{
	return [self writeNBytes: [str cStringLength]
		      fromBuffer: [str cString]];
}

- (size_t)writeLine: (OFString*)str
{
	size_t len = [str cStringLength];
	char *buf;
	size_t ret = [self writeString: str];
	[self writeInt8: '\n'];

	buf = [self allocMemoryWithSize: len + 1];

	@try {
		memcpy(buf, [str cString], len);
		buf[len] = '\n';

	return ret + 1;
		return [self writeNBytes: len + 1
			      fromBuffer: buf];
	} @finally {
		[self freeMemory: buf];
	}
}

- (size_t)writeFormat: (OFString*)fmt, ...
{
	va_list args;
	size_t ret;