ObjFW  Diff

Differences From Artifact [d98f273881]:

To Artifact [9c40edc919]:


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33


34
35
36
37
38
39
40

#include <stdlib.h>
#include <string.h>
#include <limits.h>

#import "OFData.h"
#import "OFData+Private.h"
#import "OFString.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
# import "OFFileManager.h"
#endif
#import "OFURL.h"
#import "OFDictionary.h"
#import "OFXMLElement.h"
#import "OFSystemInfo.h"



#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"







|




|
|
|
|
>
>







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

#include <stdlib.h>
#include <string.h>
#include <limits.h>

#import "OFData.h"
#import "OFData+Private.h"
#import "OFDictionary.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
# import "OFFileManager.h"
#endif
#import "OFStream.h"
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFURL.h"
#import "OFURLHandler.h"
#import "OFXMLElement.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
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
261
262
263
264
265
		@throw e;
	}

	return self;
}
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
- (instancetype)initWithContentsOfURL: (OFURL *)URL
{
	void *pool;
	OFString *scheme;


	pool = objc_autoreleasePoolPush();







	scheme = [URL scheme];



# ifdef OF_HAVE_FILES
	if ([scheme isEqual: @"file"])

		self = [self initWithContentsOfFile:
		    [URL fileSystemRepresentation]];



	else
# endif
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];







	objc_autoreleasePoolPop(pool);





	return self;
}
#endif

- (instancetype)initWithStringRepresentation: (OFString *)string
{
	self = [super init];

	@try {
		size_t count = [string







<


<
|

>
|
>
>
>
>

>
>
|

>
>
|
<
>
|
|
>
>
>
|
|
|

>
>
>
>
>
>
|
>
>
>
|
>


<







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
261
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
		@throw e;
	}

	return self;
}
#endif


- (instancetype)initWithContentsOfURL: (OFURL *)URL
{

	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFURLHandler *URLHandler;
		OFStream *stream;
		size_t pageSize;
		unsigned char *buffer;

		if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
			@throw [OFUnsupportedProtocolException
			    exceptionWithURL: URL];

		_itemSize = 1;
		_count = 0;


		pageSize = [OFSystemInfo pageSize];
		buffer = [self allocMemoryWithSize: pageSize];

		while (![stream isAtEndOfStream]) {
			size_t length = [stream readIntoBuffer: buffer
							length: pageSize];

			if (SIZE_MAX - _count < length)
				@throw [OFOutOfRangeException exception];

			_items = [self resizeMemory: _items
					       size: _count + length];
			memcpy(_items + _count, buffer, length);
			_count += length;
		}

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}


- (instancetype)initWithStringRepresentation: (OFString *)string
{
	self = [super init];

	@try {
		size_t count = [string