ObjFW  Check-in [4b637f8516]

Overview
Comment:Add OFSystemInfo.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4b637f851634d1975f7fc226cd085f639f8f40ef24612ae9206a90165f0ccd13
User & Date: js on 2012-12-26 14:10:34
Other Links: manifest | tags
Context
2012-12-26
14:10
OFProcess: Add a parameter for the environment. check-in: 891c0faad4 user: js tags: trunk
14:10
Add OFSystemInfo. check-in: 4b637f8516 user: js tags: trunk
2012-12-22
15:37
Xcode project: Set deployment target to default. check-in: 57a82682ae user: js tags: trunk
Changes

Modified ObjFW.xcodeproj/project.pbxproj from [1c5bab7363] to [acdd41e87d].

284
285
286
287
288
289
290


291
292
293
294
295
296
297
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299







+
+







		4B674402163C395900EB1E59 /* OFLocking.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743F9163C395900EB1E59 /* OFLocking.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B674403163C395900EB1E59 /* OFMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743FA163C395900EB1E59 /* OFMutex.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B674404163C395900EB1E59 /* OFMutex.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6743FB163C395900EB1E59 /* OFMutex.m */; };
		4B674405163C395900EB1E59 /* OFRecursiveMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743FC163C395900EB1E59 /* OFRecursiveMutex.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B674406163C395900EB1E59 /* OFRecursiveMutex.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6743FD163C395900EB1E59 /* OFRecursiveMutex.m */; };
		4B674407163C395900EB1E59 /* OFTLSKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743FE163C395900EB1E59 /* OFTLSKey.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B674408163C395900EB1E59 /* OFTLSKey.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6743FF163C395900EB1E59 /* OFTLSKey.m */; };
		4B745BA5168B25E600A6C20E /* OFSystemInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B745BA3168B25E600A6C20E /* OFSystemInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B745BA6168B25E600A6C20E /* OFSystemInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B745BA4168B25E600A6C20E /* OFSystemInfo.m */; };
		4B7FF3B4133CED6200000324 /* OFConditionStillWaitingException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B7FF3B2133CED6100000324 /* OFConditionStillWaitingException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B7FF3B5133CED6200000324 /* OFConditionStillWaitingException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B7FF3B3133CED6100000324 /* OFConditionStillWaitingException.m */; };
		4B837D7916829C5F007A3E83 /* block.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B837D7716829C5F007A3E83 /* block.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B837D7A16829C5F007A3E83 /* instance.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B837D7816829C5F007A3E83 /* instance.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B83F0F4142FDEFD00E4A821 /* OFStreamObserver_kqueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B83F0F2142FDEFD00E4A821 /* OFStreamObserver_kqueue.h */; };
		4B83F0F5142FDEFD00E4A821 /* OFStreamObserver_kqueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B83F0F3142FDEFD00E4A821 /* OFStreamObserver_kqueue.m */; };
		4B8B16FE133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8B16FC133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
685
686
687
688
689
690
691


692
693
694
695
696
697
698
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702







+
+







		4B6EF67C1235358D0076B512 /* OFXMLElementBuilderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLElementBuilderTests.m; path = tests/OFXMLElementBuilderTests.m; sourceTree = SOURCE_ROOT; };
		4B6EF67E1235358D0076B512 /* OFXMLParserTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLParserTests.m; path = tests/OFXMLParserTests.m; sourceTree = SOURCE_ROOT; };
		4B6EF67F1235358D0076B512 /* PropertiesTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PropertiesTests.m; path = tests/PropertiesTests.m; sourceTree = SOURCE_ROOT; };
		4B6EF6801235358D0076B512 /* TestsAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestsAppDelegate.h; path = tests/TestsAppDelegate.h; sourceTree = SOURCE_ROOT; };
		4B6EF6811235358D0076B512 /* TestsAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestsAppDelegate.m; path = tests/TestsAppDelegate.m; sourceTree = SOURCE_ROOT; };
		4B6EF684123535B60076B512 /* TestPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestPlugin.m; path = tests/plugin/TestPlugin.m; sourceTree = SOURCE_ROOT; };
		4B6EF685123535C80076B512 /* test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = test.m; path = tests/objc_sync/test.m; sourceTree = SOURCE_ROOT; };
		4B745BA3168B25E600A6C20E /* OFSystemInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSystemInfo.h; path = src/OFSystemInfo.h; sourceTree = "<group>"; };
		4B745BA4168B25E600A6C20E /* OFSystemInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSystemInfo.m; path = src/OFSystemInfo.m; sourceTree = "<group>"; };
		4B7FF3B2133CED6100000324 /* OFConditionStillWaitingException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFConditionStillWaitingException.h; path = src/exceptions/OFConditionStillWaitingException.h; sourceTree = "<group>"; };
		4B7FF3B3133CED6100000324 /* OFConditionStillWaitingException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFConditionStillWaitingException.m; path = src/exceptions/OFConditionStillWaitingException.m; sourceTree = "<group>"; };
		4B837D7716829C5F007A3E83 /* block.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = block.h; path = src/block.h; sourceTree = "<group>"; };
		4B837D7816829C5F007A3E83 /* instance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = instance.h; path = src/instance.h; sourceTree = "<group>"; };
		4B83F0F2142FDEFD00E4A821 /* OFStreamObserver_kqueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamObserver_kqueue.h; path = src/OFStreamObserver_kqueue.h; sourceTree = "<group>"; };
		4B83F0F3142FDEFD00E4A821 /* OFStreamObserver_kqueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver_kqueue.m; path = src/OFStreamObserver_kqueue.m; sourceTree = "<group>"; };
		4B8B16FC133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFHashAlreadyCalculatedException.h; path = src/exceptions/OFHashAlreadyCalculatedException.h; sourceTree = "<group>"; };
1175
1176
1177
1178
1179
1180
1181


1182
1183
1184
1185
1186
1187
1188
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194







+
+







				4BF1BCC911C9663F0025511F /* OFString+URLEncoding.m */,
				4BF1BCCA11C9663F0025511F /* OFString+XMLEscaping.h */,
				4BF1BCCB11C9663F0025511F /* OFString+XMLEscaping.m */,
				4BF1BCCC11C9663F0025511F /* OFString+XMLUnescaping.h */,
				4BF1BCCD11C9663F0025511F /* OFString+XMLUnescaping.m */,
				4B552550147AA5DB0003BF47 /* OFString_UTF8.h */,
				4B552551147AA5DB0003BF47 /* OFString_UTF8.m */,
				4B745BA3168B25E600A6C20E /* OFSystemInfo.h */,
				4B745BA4168B25E600A6C20E /* OFSystemInfo.m */,
				4B6799811099E7C50041064A /* OFTCPSocket.h */,
				4B6799821099E7C50041064A /* OFTCPSocket.m */,
				4BD653C3143B8489006182F0 /* OFTCPSocket+SOCKS5.h */,
				4BD653C4143B8489006182F0 /* OFTCPSocket+SOCKS5.m */,
				4B6799831099E7C50041064A /* OFThread.h */,
				4B6799841099E7C50041064A /* OFThread.m */,
				4B9361A61511000C00DCD16B /* OFThreadPool.h */,
1397
1398
1399
1400
1401
1402
1403

1404
1405
1406
1407
1408
1409
1410
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417







+







				4B3D23D81337FCB000DD29B8 /* OFString.h in Headers */,
				4B3D23D91337FCB000DD29B8 /* OFString+Hashing.h in Headers */,
				4B5CF8F914940BD2007AA324 /* OFString+JSONValue.h in Headers */,
				4BB25E8A139C388A00F574EA /* OFString+Serialization.h in Headers */,
				4B3D23DA1337FCB000DD29B8 /* OFString+URLEncoding.h in Headers */,
				4B3D23DB1337FCB000DD29B8 /* OFString+XMLEscaping.h in Headers */,
				4B3D23DC1337FCB000DD29B8 /* OFString+XMLUnescaping.h in Headers */,
				4B745BA5168B25E600A6C20E /* OFSystemInfo.h in Headers */,
				4B3D23DD1337FCB000DD29B8 /* OFTCPSocket.h in Headers */,
				4B3D23DE1337FCB000DD29B8 /* OFThread.h in Headers */,
				4B9361A81511000C00DCD16B /* OFThreadPool.h in Headers */,
				4B325EDF1605F3A0007836CA /* OFTimer.h in Headers */,
				4B674407163C395900EB1E59 /* OFTLSKey.h in Headers */,
				4BA02BA215041F5900002F84 /* OFTLSSocket.h in Headers */,
				4B3D23DF1337FCB000DD29B8 /* OFURL.h in Headers */,
1750
1751
1752
1753
1754
1755
1756

1757
1758
1759
1760
1761
1762
1763
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771







+







				4B3D23A71337FC0D00DD29B8 /* OFString+Hashing.m in Sources */,
				4B5CF8FA14940BD2007AA324 /* OFString+JSONValue.m in Sources */,
				4BB25E8B139C388A00F574EA /* OFString+Serialization.m in Sources */,
				4B3D23A81337FC0D00DD29B8 /* OFString+URLEncoding.m in Sources */,
				4B3D23A91337FC0D00DD29B8 /* OFString+XMLEscaping.m in Sources */,
				4B3D23AA1337FC0D00DD29B8 /* OFString+XMLUnescaping.m in Sources */,
				4B552555147AA5DB0003BF47 /* OFString_UTF8.m in Sources */,
				4B745BA6168B25E600A6C20E /* OFSystemInfo.m in Sources */,
				4B3D23AB1337FC0D00DD29B8 /* OFTCPSocket.m in Sources */,
				4BD653C6143B8489006182F0 /* OFTCPSocket+SOCKS5.m in Sources */,
				4B3D23AC1337FC0D00DD29B8 /* OFThread.m in Sources */,
				4B9361A91511000C00DCD16B /* OFThreadPool.m in Sources */,
				4B325EE01605F3A0007836CA /* OFTimer.m in Sources */,
				4B674408163C395900EB1E59 /* OFTLSKey.m in Sources */,
				4B3D23AD1337FC0D00DD29B8 /* OFURL.m in Sources */,

Modified src/Makefile from [d6b3564105] to [c09179d8ec].

49
50
51
52
53
54
55

56
57
58
59
60
61
62
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63







+







       OFString.m			\
       OFString+Hashing.m		\
       OFString+JSONValue.m		\
       OFString+Serialization.m		\
       OFString+URLEncoding.m		\
       OFString+XMLEscaping.m		\
       OFString+XMLUnescaping.m		\
       OFSystemInfo.m			\
       OFTCPSocket.m			\
       OFTimer.m			\
       OFURL.m				\
       OFXMLAttribute.m			\
       OFXMLCDATA.m			\
       OFXMLCharacters.m		\
       OFXMLComment.m			\

Modified src/OFDataArray.m from [b9544608cd] to [15f68d4242].

23
24
25
26
27
28
29

30
31
32
33
34
35
36
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37







+







#import "OFDataArray.h"
#import "OFString.h"
#import "OFFile.h"
#import "OFURL.h"
#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFXMLElement.h"
#import "OFSystemInfo.h"

#import "OFHTTPRequestFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

108
109
110
111
112
113
114

115

116
117
118
119
120
121

122
123
124
125
126
127
128
109
110
111
112
113
114
115
116

117
118
119
120
121
122

123
124
125
126
127
128
129
130







+
-
+





-
+







	@try {
		OFFile *file = [[OFFile alloc] initWithPath: path
						       mode: @"rb"];

		itemSize = 1;

		@try {
			size_t pageSize = [OFSystemInfo pageSize];
			char *buffer = [self allocMemoryWithSize: of_pagesize];
			char *buffer = [self allocMemoryWithSize: pageSize];

			while (![file isAtEndOfStream]) {
				size_t length;

				length = [file readIntoBuffer: buffer
						       length: of_pagesize];
						       length: pageSize];
				[self addItems: buffer
					 count: length];
			}

			[self freeMemory: buffer];
		} @finally {
			[file release];
579
580
581
582
583
584
585
586

587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

608
609
610
611
612
613
614
581
582
583
584
585
586
587

588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608

609
610
611
612
613
614
615
616







-
+




















-
+







- (void)addItem: (const void*)item
{
	size_t newSize, lastPageByte;

	if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemSize)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	lastPageByte = of_pagesize - 1;
	lastPageByte = [OFSystemInfo pageSize] - 1;
	newSize = ((count + 1) * itemSize + lastPageByte) & ~lastPageByte;

	if (size != newSize)
		items = [self resizeMemory: items
				      size: newSize];

	memcpy(items + count * itemSize, item, itemSize);

	count++;
	size = newSize;
}

- (void)addItems: (const void*)items_
	   count: (size_t)count_
{
	size_t newSize, lastPageByte;

	if (count_ > SIZE_MAX - count || count + count_ > SIZE_MAX / itemSize)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	lastPageByte = of_pagesize - 1;
	lastPageByte = [OFSystemInfo pageSize] - 1;
	newSize = ((count + count_) * itemSize + lastPageByte) & ~lastPageByte;

	if (size != newSize)
		items = [self resizeMemory: items
				      size: newSize];

	memcpy(items + count * itemSize, items_, count_ * itemSize);
623
624
625
626
627
628
629
630

631
632
633
634
635
636
637
625
626
627
628
629
630
631

632
633
634
635
636
637
638
639







-
+







{
	size_t newSize, lastPageByte;

	if (count_ > SIZE_MAX - count || index > count ||
	    count + count_ > SIZE_MAX / itemSize)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	lastPageByte = of_pagesize - 1;
	lastPageByte = [OFSystemInfo pageSize] - 1;
	newSize = ((count + count_) * itemSize + lastPageByte) & ~lastPageByte;

	if (size != newSize)
		items = [self resizeMemory: items
				      size: newSize];

	memmove(items + (index + count_) * itemSize, items + index * itemSize,
651
652
653
654
655
656
657
658

659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675

676
677
678
679
680
681
682
653
654
655
656
657
658
659

660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676

677
678
679
680
681
682
683
684







-
+
















-
+







		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	memmove(items + range.location * itemSize,
	    items + (range.location + range.length) * itemSize,
	    (count - range.location - range.length) * itemSize);

	count -= range.length;
	lastPageByte = of_pagesize - 1;
	lastPageByte = [OFSystemInfo pageSize] - 1;
	newSize = (count * itemSize + lastPageByte) & ~lastPageByte;

	if (size != newSize)
		items = [self resizeMemory: items
				      size: newSize];
	size = newSize;
}

- (void)removeLastItem
{
	size_t newSize, lastPageByte;

	if (count == 0)
		return;

	count--;
	lastPageByte = of_pagesize - 1;
	lastPageByte = [OFSystemInfo pageSize] - 1;
	newSize = (count * itemSize + lastPageByte) & ~lastPageByte;

	if (size != newSize) {
		@try {
			items = [self resizeMemory: items
					      size: newSize];
		} @catch (OFOutOfMemoryException *e) {

Modified src/OFDate.m from [2efbaabb9c] to [7d0fdfaed1].

28
29
30
31
32
33
34

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







+







#import "OFDate.h"
#import "OFString.h"
#import "OFDictionary.h"
#import "OFXMLElement.h"
#ifdef OF_THREADS
# import "OFMutex.h"
#endif
#import "OFSystemInfo.h"

#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"

#import "autorelease.h"
510
511
512
513
514
515
516

517
518
519
520
521
522
523
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525







+







}

- (OFString*)dateStringWithFormat: (OFConstantString*)format
{
	OFString *ret;
	time_t seconds_ = (time_t)seconds;
	struct tm tm;
	size_t pageSize;
	char *buffer;

	if (seconds_ != floor(seconds))
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

#ifdef HAVE_GMTIME_R
	if (gmtime_r(&seconds_, &tm) == NULL)
538
539
540
541
542
543
544

545

546
547
548

549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564

565
566
567
568
569
570
571
540
541
542
543
544
545
546
547

548
549
550

551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575







+
-
+


-
+
















+







# ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
# endif
#endif

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

	@try {
		if (!strftime(buffer, of_pagesize, [format UTF8String], &tm))
		if (!strftime(buffer, pageSize, [format UTF8String], &tm))
			@throw [OFOutOfRangeException
			    exceptionWithClass: [self class]];

		ret = [OFString stringWithUTF8String: buffer];
	} @finally {
		[self freeMemory: buffer];
	}

	return ret;
}

- (OFString*)localDateStringWithFormat: (OFConstantString*)format
{
	OFString *ret;
	time_t seconds_ = (time_t)seconds;
	struct tm tm;
	size_t pageSize;
	char *buffer;

	if (seconds_ != floor(seconds))
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

#ifdef HAVE_LOCALTIME_R
	if (localtime_r(&seconds_, &tm) == NULL)
586
587
588
589
590
591
592

593

594
595
596

597
598
599
600
601
602
603
590
591
592
593
594
595
596
597

598
599
600

601
602
603
604
605
606
607
608







+
-
+


-
+







# ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
# endif
#endif

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

	@try {
		if (!strftime(buffer, of_pagesize, [format UTF8String], &tm))
		if (!strftime(buffer, pageSize, [format UTF8String], &tm))
			@throw [OFOutOfRangeException
			    exceptionWithClass: [self class]];

		ret = [OFString stringWithUTF8String: buffer];
	} @finally {
		[self freeMemory: buffer];
	}

Modified src/OFFile.m from [b3c8f30967] to [61775ac9b0].

44
45
46
47
48
49
50

51
52
53
54
55
56
57
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58







+







#import "OFString.h"
#import "OFArray.h"
#ifdef OF_THREADS
# import "threading.h"
#endif
#import "OFDate.h"
#import "OFApplication.h"
#import "OFSystemInfo.h"

#import "OFChangeDirectoryFailedException.h"
#import "OFChangeFileModeFailedException.h"
#import "OFChangeFileOwnerFailedException.h"
#import "OFCreateDirectoryFailedException.h"
#import "OFDeleteDirectoryFailedException.h"
#import "OFDeleteFileFailedException.h"
494
495
496
497
498
499
500

501
502
503
504
505
506
507
508

509
510

511
512

513
514
515
516
517
518
519
520
521
522
523
524

525
526
527
528
529
530
531
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512

513
514

515
516
517
518
519
520
521
522
523
524
525
526

527
528
529
530
531
532
533
534







+








+

-
+

-
+











-
+







		toPath: (OFString*)destination
{
	void *pool = objc_autoreleasePoolPush();
	BOOL override;
	OFFile *sourceFile = nil;
	OFFile *destinationFile = nil;
	char *buffer;
	size_t pageSize;

	if ([self directoryExistsAtPath: destination]) {
		OFString *filename = [source lastPathComponent];
		destination = [OFString stringWithPath: destination, filename,
							nil];
	}

	override = [self fileExistsAtPath: destination];
	pageSize = [OFSystemInfo pageSize];

	if ((buffer = malloc(of_pagesize)) == NULL)
	if ((buffer = malloc(pageSize)) == NULL)
		@throw [OFOutOfMemoryException exceptionWithClass: self
						    requestedSize: of_pagesize];
						    requestedSize: pageSize];

	@try {
		sourceFile = [OFFile fileWithPath: source
					     mode: @"rb"];
		destinationFile = [OFFile fileWithPath: destination
						  mode: @"wb"];

		while (![sourceFile isAtEndOfStream]) {
			size_t length;

			length = [sourceFile readIntoBuffer: buffer
						     length: of_pagesize];
						     length: pageSize];
			[destinationFile writeBuffer: buffer
					      length: length];
		}

#if !defined(_WIN32) && !defined(_PSP)
		if (!override) {
			struct stat s;

Modified src/OFHTTPClient.m from [993fb03183] to [f5ea4dfab5].

22
23
24
25
26
27
28

29
30
31
32
33
34
35
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36







+







#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFString.h"
#import "OFURL.h"
#import "OFTCPSocket.h"
#import "OFDictionary.h"
#import "OFDataArray.h"
#import "OFSystemInfo.h"

#import "OFHTTPRequestFailedException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
127
128
129
130
131
132
133

134
135
136
137
138
139
140
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142







+







	OFDataArray *data;
	OFEnumerator *keyEnumerator, *objectEnumerator;
	OFString *key, *object, *contentLengthHeader;
	int status;
	const char *type = NULL;
	size_t contentLength = 0;
	BOOL chunked;
	size_t pageSize;
	char *buffer;
	size_t bytesReceived;

	if (![scheme isEqual: @"http"] && ![scheme isEqual: @"https"])
		@throw [OFUnsupportedProtocolException
		    exceptionWithClass: [self class]
				   URL: URL];
357
358
359
360
361
362
363

364

365
366
367
368
369
370
371
359
360
361
362
363
364
365
366

367
368
369
370
371
372
373
374







+
-
+







		contentLength = (size_t)[contentLengthHeader decimalValue];

		if (contentLength > SIZE_MAX)
			@throw [OFOutOfRangeException
			    exceptionWithClass: [self class]];
	}

	pageSize = [OFSystemInfo pageSize];
	buffer = [self allocMemoryWithSize: of_pagesize];
	buffer = [self allocMemoryWithSize: pageSize];
	bytesReceived = 0;
	@try {
		if (chunked) {
			for (;;) {
				void *pool2 = objc_autoreleasePoolPush();
				size_t toRead;
				of_range_t range;
392
393
394
395
396
397
398
399
400


401
402
403
404
405
406
407
395
396
397
398
399
400
401


402
403
404
405
406
407
408
409
410







-
-
+
+








				if (toRead == 0 ||
				    (contentLengthHeader != nil &&
				    contentLength >= bytesReceived))
					break;

				while (toRead > 0) {
					size_t length = (toRead < of_pagesize
					    ? toRead : of_pagesize);
					size_t length = (toRead < pageSize
					    ? toRead : pageSize);

					length = [sock readIntoBuffer: buffer
							       length: length];

					if ([delegate respondsToSelector:
					    @selector(client:didReceiveData:
					    length:request:)])
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453







-
+







		} else {
			size_t length;

			while (![sock isAtEndOfStream]) {
				void *pool2;

				length = [sock readIntoBuffer: buffer
						       length: of_pagesize];
						       length: pageSize];

				pool2 = objc_autoreleasePoolPush();

				if ([delegate respondsToSelector:
				    @selector(client:didReceiveData:length:
				    request:)])
					[delegate client: self

Modified src/OFObject.h from [fdedfa544a] to [24db658a1c].

883
884
885
886
887
888
889
890
891
892
893
894
895
883
884
885
886
887
888
889


890
891
892
893







-
-




#import "OFObject+Serialization.h"

#ifdef __cplusplus
extern "C" {
#endif
extern id of_alloc_object(Class class_, size_t extraSize, size_t extraAlignment,
    void **extra);
extern size_t of_pagesize;
extern size_t of_num_cpus;
extern uint32_t of_hash_seed;
#ifdef __cplusplus
}
#endif

Modified src/OFObject.m from [23e21a638e] to [6afd10fb87].

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
12
13
14
15
16
17
18


19
20
21
22


23
24
25
26




27
28
29
30
31
32
33







-
-




-
-




-
-
-
-







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#define __NO_EXT_QNX

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

#include <unistd.h>

#include <assert.h>

#include <sys/time.h>

#ifdef __QNX__
# include <sys/syspage.h>
#endif

#import "OFObject.h"
#import "OFTimer.h"
#import "OFThread.h"
#import "OFRunLoop.h"
#import "OFAutoreleasePool.h"

#import "OFAllocFailedException.h"
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
87
88
89
90
91
92
93


94
95
96
97
98
99
100







-
-







	(__BIGGEST_ALIGNMENT__ - 1)) & ~(__BIGGEST_ALIGNMENT__ - 1))
#define PRE_MEM(mem) ((struct pre_mem*)(void*)((char*)mem - PRE_MEM_ALIGN))

static struct {
	Class isa;
} alloc_failed_exception;

size_t of_pagesize;
size_t of_num_cpus;
uint32_t of_hash_seed;

#if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__)
static void
uncaught_exception_handler(id exception)
{
	fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n",
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
287
288
289
290
291
248
249
250
251
252
253
254




















255
256
257
258
259
260
261







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	objc_setForwardHandler(of_forward, of_forward_stret);
#endif

#ifdef HAVE_OBJC_ENUMERATIONMUTATION
	objc_setEnumerationMutationHandler(enumeration_mutation_handler);
#endif

#if defined(_WIN32)
	SYSTEM_INFO si;
	GetSystemInfo(&si);
	of_pagesize = si.dwPageSize;
	of_num_cpus = si.dwNumberOfProcessors;
#elif defined(__QNX__)
	if ((of_pagesize = sysconf(_SC_PAGESIZE)) < 1)
		of_pagesize = 4096;
	of_num_cpus = _syspage_ptr->num_cpu;
#else
# ifdef _SC_PAGESIZE
	if ((of_pagesize = sysconf(_SC_PAGESIZE)) < 1)
# endif
		of_pagesize = 4096;
# ifdef _SC_NPROCESSORS_CONF
	if ((of_num_cpus = sysconf(_SC_NPROCESSORS_CONF)) < 1)
# endif
		of_num_cpus = 1;
#endif

#if defined(OF_HAVE_ARC4RANDOM)
	of_hash_seed = arc4random();
#elif defined(OF_HAVE_RANDOM)
	struct timeval t;
	gettimeofday(&t, NULL);
	srandom((unsigned)(t.tv_sec ^ t.tv_usec));
	of_hash_seed = (uint32_t)((random() << 16) | (random() & 0xFFFF));

Modified src/OFStream.m from [31e482b9ed] to [17a340fbd1].

30
31
32
33
34
35
36

37
38
39
40
41
42
43
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







+







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

#import "OFStream.h"
#import "OFString.h"
#import "OFDataArray.h"
#import "OFSystemInfo.h"
#import "OFRunLoop.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFSetOptionFailedException.h"

#import "macros.h"
510
511
512
513
514
515
516

517
518
519

520

521
522
523
524
525
526
527

528
529
530
531
532
533
534
511
512
513
514
515
516
517
518
519
520
521
522

523
524
525
526
527
528
529

530
531
532
533
534
535
536
537







+



+
-
+






-
+








	return dataArray;
}

- (OFDataArray*)readDataArrayTillEndOfStream
{
	OFDataArray *dataArray;
	size_t pageSize;
	char *buffer;

	dataArray = [OFDataArray dataArray];
	pageSize = [OFSystemInfo pageSize];
	buffer = [self allocMemoryWithSize: of_pagesize];
	buffer = [self allocMemoryWithSize: pageSize];

	@try {
		while (![self isAtEndOfStream]) {
			size_t length;

			length = [self readIntoBuffer: buffer
					       length: of_pagesize];
					       length: pageSize];
			[dataArray addItems: buffer
				      count: length];
		}
	} @finally {
		[self freeMemory: buffer];
	}

559
560
561
562
563
564
565
566

567
568
569
570
571
572
573
562
563
564
565
566
567
568

569
570
571
572
573
574
575
576







-
+







	}

	return ret;
}

- (OFString*)tryReadLineWithEncoding: (of_string_encoding_t)encoding
{
	size_t i, bufferLength, retLength;
	size_t i, pageSize, bufferLength, retLength;
	char *retCString, *buffer, *newCache;
	OFString *ret;

	/* Look if there's a line or \0 in our cache */
	if (!waitingForDelimiter && cache != NULL) {
		for (i = 0; i < cacheLength; i++) {
			if OF_UNLIKELY (cache[i] == '\n' || cache[i] == '\0') {
592
593
594
595
596
597
598
599
600



601
602
603
604
605
606
607
595
596
597
598
599
600
601


602
603
604
605
606
607
608
609
610
611







-
-
+
+
+








				waitingForDelimiter = NO;
				return ret;
			}
		}
	}

	/* Read and see if we get a newline or \0 */
	buffer = [self allocMemoryWithSize: of_pagesize];
	/* Read and see if we got a newline or \0 */
	pageSize = [OFSystemInfo pageSize];
	buffer = [self allocMemoryWithSize: pageSize];

	@try {
		if ([self lowlevelIsAtEndOfStream]) {
			if (cache == NULL) {
				waitingForDelimiter = NO;
				return nil;
			}
620
621
622
623
624
625
626
627

628
629
630
631
632
633
634
624
625
626
627
628
629
630

631
632
633
634
635
636
637
638







-
+







			cacheLength = 0;

			waitingForDelimiter = NO;
			return ret;
		}

		bufferLength = [self lowlevelReadIntoBuffer: buffer
						     length: of_pagesize];
						     length: pageSize];

		/* Look if there's a newline or \0 */
		for (i = 0; i < bufferLength; i++) {
			if OF_UNLIKELY (buffer[i] == '\n' ||
			    buffer[i] == '\0') {
				retLength = cacheLength + i;
				retCString = [self
761
762
763
764
765
766
767
768

769
770
771
772
773
774
775
765
766
767
768
769
770
771

772
773
774
775
776
777
778
779







-
+







	return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8];
}

- (OFString*)tryReadTillDelimiter: (OFString*)delimiter
			 encoding: (of_string_encoding_t)encoding
{
	const char *delimiterCString;
	size_t i, j, delimiterLength, bufferLength, retLength;
	size_t i, j, delimiterLength, pageSize, bufferLength, retLength;
	char *retCString, *buffer, *newCache;
	OFString *ret;

	delimiterCString = [delimiter cStringUsingEncoding: encoding];
	delimiterLength = [delimiter lengthOfBytesUsingEncoding: encoding];
	j = 0;

805
806
807
808
809
810
811
812
813



814
815
816
817
818
819
820
809
810
811
812
813
814
815


816
817
818
819
820
821
822
823
824
825







-
-
+
+
+








				waitingForDelimiter = NO;
				return ret;
			}
		}
	}

	/* Read and see if we get a delimiter or \0 */
	buffer = [self allocMemoryWithSize: of_pagesize];
	/* Read and see if we got a delimiter or \0 */
	pageSize = [OFSystemInfo pageSize];
	buffer = [self allocMemoryWithSize: pageSize];

	@try {
		if ([self lowlevelIsAtEndOfStream]) {
			if (cache == NULL) {
				waitingForDelimiter = NO;
				return nil;
			}
828
829
830
831
832
833
834
835

836
837
838
839
840
841
842
833
834
835
836
837
838
839

840
841
842
843
844
845
846
847







-
+







			cacheLength = 0;

			waitingForDelimiter = NO;
			return ret;
		}

		bufferLength = [self lowlevelReadIntoBuffer: buffer
						     length: of_pagesize];
						     length: pageSize];

		/* Look if there's a delimiter or \0 */
		for (i = 0; i < bufferLength; i++) {
			if (buffer[i] != delimiterCString[j++])
				j = 0;

			if (j == delimiterLength || buffer[i] == '\0') {

Added src/OFSystemInfo.h version [bc0281aac5].







































1
2
3
4
5
6
7
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"

/*!
 * @brief A class for querying information about the system.
 */
@interface OFSystemInfo: OFObject
/*!
 * @brief Returns the size of a page.
 *
 * @return The size of a page
 */
+ (size_t)pageSize;

/*!
 * @brief Returns the number of CPUs installed in the system.
 *
 * A CPU with multiple cores counts as multiple CPUs.
 *
 * @return The number of CPUs installed in the system
 */
+ (size_t)numberOfCPUs;
@end

Added src/OFSystemInfo.m version [aa3fde574a].













































































1
2
3
4
5
6
7
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#define __NO_EXT_QNX

#import "OFSystemInfo.h"

#include <stdlib.h>

#include <unistd.h>

#ifdef __QNX__
# include <sys/syspage.h>
#endif

static size_t pageSize;
static size_t numberOfCPUs;

@implementation OFSystemInfo
+ (void)initialize
{
	if (self != [OFSystemInfo class])
		return;

#if defined(_WIN32)
	SYSTEM_INFO si;
	GetSystemInfo(&si);
	pageSize = si.dwPageSize;
	numberOfCPUs = si.dwNumberOfProcessors;
#elif defined(__QNX__)
	if ((pageSize = sysconf(_SC_PAGESIZE)) < 1)
		pageSize = 4096;
	numberOfCPUs = _syspage_ptr->num_cpu;
#else
# ifdef _SC_PAGESIZE
	if ((pageSize = sysconf(_SC_PAGESIZE)) < 1)
# endif
		numberOfCPUs = 4096;
# ifdef _SC_NPROCESSORS_CONF
	if ((numberOfCPUs = sysconf(_SC_NPROCESSORS_CONF)) < 1)
# endif
		numberOfCPUs = 1;
#endif
}

+ alloc
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}

+ (size_t)pageSize
{
	return pageSize;
}

+ (size_t)numberOfCPUs
{
	return numberOfCPUs;
}
@end

Modified src/OFThreadPool.m from [5b323e884d] to [588dc64cd5].

17
18
19
20
21
22
23

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







+







#include "config.h"

#import "OFThreadPool.h"
#import "OFArray.h"
#import "OFList.h"
#import "OFThread.h"
#import "OFCondition.h"
#import "OFSystemInfo.h"

#import "autorelease.h"

@interface OFThreadPoolJob: OFObject
{
	id target;
	SEL selector;
250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265







-
+







+ (instancetype)threadPoolWithSize: (size_t)size
{
	return [[[self alloc] initWithSize: size] autorelease];
}

- init
{
	return [self initWithSize: of_num_cpus];
	return [self initWithSize: [OFSystemInfo numberOfCPUs]];
}

- initWithSize: (size_t)size_
{
	self = [super init];

	@try {

Modified src/OFXMLParser.m from [6b0673d037] to [e91c2714f2].

24
25
26
27
28
29
30

31
32
33
34
35
36
37
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38







+







#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFDataArray.h"
#import "OFXMLAttribute.h"
#import "OFStream.h"
#import "OFFile.h"
#import "OFSystemInfo.h"

#import "OFInitializationFailedException.h"
#import "OFMalformedXMLException.h"
#import "OFUnboundNamespaceException.h"

#import "autorelease.h"
#import "macros.h"
275
276
277
278
279
280
281

282

283
284
285
286
287

288
289
290
291
292
293
294
276
277
278
279
280
281
282
283

284
285
286
287
288

289
290
291
292
293
294
295
296







+
-
+




-
+







{
	[self parseBuffer: [string UTF8String]
		   length: [string UTF8StringLength]];
}

- (void)parseStream: (OFStream*)stream
{
	size_t pageSize = [OFSystemInfo pageSize];
	char *buffer = [self allocMemoryWithSize: of_pagesize];
	char *buffer = [self allocMemoryWithSize: pageSize];

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

			[self parseBuffer: buffer
				   length: length];
		}
	} @finally {
		[self freeMemory: buffer];
	}

Modified src/autorelease.m from [54e2ae018c] to [b7a742a674].

16
17
18
19
20
21
22

23
24
25
26
27
28
29
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30







+








#include "config.h"

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

#import "OFObject.h"
#import "OFSystemInfo.h"

#ifndef OF_COMPILER_TLS
# import "threading.h"
#endif
#import "macros.h"

#import "autorelease.h"
90
91
92
93
94
95
96


97

98
99
100
101
102
103
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
91
92
93
94
95
96
97
98
99

100
101
102

103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120







+
+
-
+


-










-
+







#ifndef OF_COMPILER_TLS
	id *top = of_tlskey_get(topKey);
	id *objects = of_tlskey_get(objectsKey);
	size_t size = (size_t)(uintptr_t)of_tlskey_get(sizeKey);
#endif

	if (objects == NULL) {
		size = [OFSystemInfo pageSize];

		OF_ENSURE((objects = malloc(of_pagesize)) != NULL);
		OF_ENSURE((objects = malloc(size)) != NULL);

		top = objects;
		size = of_pagesize;

#ifndef OF_COMPILER_TLS
		OF_ENSURE(of_tlskey_set(objectsKey, objects));
		OF_ENSURE(of_tlskey_set(sizeKey, (void*)(uintptr_t)size));
#endif
	}

	if ((uintptr_t)top >= (uintptr_t)objects + size) {
		ptrdiff_t diff = top - objects;

		size += of_pagesize;
		size += [OFSystemInfo pageSize];
		OF_ENSURE((objects = realloc(objects, size)) != NULL);

#ifndef OF_COMPILER_TLS
		OF_ENSURE(of_tlskey_set(objectsKey, objects));
		OF_ENSURE(of_tlskey_set(sizeKey, (void*)(uintptr_t)size));
#endif

Modified tests/OFStreamTests.m from [6be1a5b957] to [e6328e2572].

16
17
18
19
20
21
22

23
24
25
26
27
28
29
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30







+








#include "config.h"

#include <string.h>

#import "OFStream.h"
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFAutoreleasePool.h"

#import "TestsAppDelegate.h"

static OFString *module = @"OFStream";

@interface StreamTester: OFStream
37
38
39
40
41
42
43


44
45
46
47
48
49
50
51
52
53
54

55
56
57
58

59
60
61

62
63
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78



79
80
81

82
83
84
85
86
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60

61
62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79



80
81
82
83
84

85
86
87
88
89
90







+
+










-
+



-
+


-
+










+




-
-
-
+
+
+


-
+





{
	return (state > 1 ? YES : NO);
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)size
{
	size_t pageSize = [OFSystemInfo pageSize];

	switch (state) {
	case 0:
		if (size < 1)
			return 0;

		memcpy(buffer, "f", 1);

		state++;
		return 1;
	case 1:
		if (size < of_pagesize)
		if (size < pageSize)
			return 0;

		memcpy(buffer, "oo\n", 3);
		memset((char*)buffer + 3, 'X', of_pagesize - 3);
		memset((char*)buffer + 3, 'X', pageSize - 3);

		state++;
		return of_pagesize;
		return pageSize;
	}

	return 0;
}
@end

@implementation TestsAppDelegate (OFStreamTests)
- (void)streamTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	size_t pageSize = [OFSystemInfo pageSize];
	StreamTester *t = [[[StreamTester alloc] init] autorelease];
	OFString *str;
	char *cstr;

	cstr = [t allocMemoryWithSize: of_pagesize - 2];
	memset(cstr, 'X', of_pagesize - 3);
	cstr[of_pagesize - 3] = '\0';
	cstr = [t allocMemoryWithSize: pageSize - 2];
	memset(cstr, 'X', pageSize - 3);
	cstr[pageSize - 3] = '\0';

	TEST(@"-[readLine]", [[t readLine] isEqual: @"foo"] &&
	    [(str = [t readLine]) length] == of_pagesize - 3 &&
	    [(str = [t readLine]) length] == pageSize - 3 &&
	    !strcmp([str UTF8String], cstr))

	[pool drain];
}
@end