ObjFW  Diff

Differences From Artifact [4230af470d]:

To Artifact [c5232e5990]:


8
9
10
11
12
13
14
15
16
17
18
19
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
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <string.h>
#include <unistd.h>
#include <assert.h>

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

#ifdef _WIN32
# include <windows.h>
#endif

static int pagesize = 0;

@implementation OFStream
- init
{
	self = [super init];

	if (isa == [OFStream class])
		@throw [OFNotImplementedException newWithClass: isa
						      selector: _cmd];

	cache = NULL;

#ifndef _WIN32
	if (pagesize == 0)
		if ((pagesize = sysconf(_SC_PAGESIZE)) == -1)
			pagesize = 4096;
#else
	if (pagesize == 0) {
		SYSTEM_INFO si;
		GetSystemInfo(&si);
		pagesize = si.dwPageSize - 1;
	}
#endif

	return self;
}

- (BOOL)atEndOfStream
{
	if (cache != NULL)
		return NO;







<







<
<
<
<
<
<











<
<
<
<
<
<
<
<
<
<
<
<







8
9
10
11
12
13
14

15
16
17
18
19
20
21






22
23
24
25
26
27
28
29
30
31
32












33
34
35
36
37
38
39
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <string.h>

#include <assert.h>

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







@implementation OFStream
- init
{
	self = [super init];

	if (isa == [OFStream class])
		@throw [OFNotImplementedException newWithClass: isa
						      selector: _cmd];

	cache = NULL;













	return self;
}

- (BOOL)atEndOfStream
{
	if (cache != NULL)
		return NO;
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

				return ret;
			}
		}
	}

	/* Read until we get a newline or \0 */
	tmp = [self allocMemoryWithSize: pagesize];

	@try {
		for (;;) {
			if ([self atEndOfStreamWithoutCache]) {
				if (cache == NULL)
					return nil;








|







121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

				return ret;
			}
		}
	}

	/* Read until we get a newline or \0 */
	tmp = [self allocMemoryWithSize: of_pagesize];

	@try {
		for (;;) {
			if ([self atEndOfStreamWithoutCache]) {
				if (cache == NULL)
					return nil;

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
				[self freeMemory: cache];
				cache = NULL;
				cache_len = 0;

				return ret;
			}

			len = [self readNBytesWithoutCache: pagesize
						intoBuffer: tmp];

			/* Look if there's a newline or \0 */
			for (i = 0; i < len; i++) {
				if (OF_UNLIKELY(tmp[i] == '\n' ||
				    tmp[i] == '\0')) {
					ret_len = cache_len + i;







|







145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
				[self freeMemory: cache];
				cache = NULL;
				cache_len = 0;

				return ret;
			}

			len = [self readNBytesWithoutCache: of_pagesize
						intoBuffer: tmp];

			/* Look if there's a newline or \0 */
			for (i = 0; i < len; i++) {
				if (OF_UNLIKELY(tmp[i] == '\n' ||
				    tmp[i] == '\0')) {
					ret_len = cache_len + i;
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

				return ret;
			}
		}
	}

	/* Read until we get the delimiter or \0 */
	tmp = [self allocMemoryWithSize: pagesize];

	@try {
		for (;;) {
			if ([self atEndOfStreamWithoutCache]) {
				if (cache == NULL)
					return nil;

				ret = [OFString stringWithCString: cache
							 encoding: encoding
							   length: cache_len];

				[self freeMemory: cache];
				cache = NULL;
				cache_len = 0;

				return ret;
			}

			len = [self readNBytesWithoutCache: pagesize
						intoBuffer: tmp];

			/* Look if there's the delimiter or \0 */
			for (i = 0; i < len; i++) {
				if (tmp[i] != delim[j++])
					j = 0;








|


















|







262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

				return ret;
			}
		}
	}

	/* Read until we get the delimiter or \0 */
	tmp = [self allocMemoryWithSize: of_pagesize];

	@try {
		for (;;) {
			if ([self atEndOfStreamWithoutCache]) {
				if (cache == NULL)
					return nil;

				ret = [OFString stringWithCString: cache
							 encoding: encoding
							   length: cache_len];

				[self freeMemory: cache];
				cache = NULL;
				cache_len = 0;

				return ret;
			}

			len = [self readNBytesWithoutCache: of_pagesize
						intoBuffer: tmp];

			/* Look if there's the delimiter or \0 */
			for (i = 0; i < len; i++) {
				if (tmp[i] != delim[j++])
					j = 0;