ObjFW  Check-in [cc34255955]

Overview
Comment:Close file on exception in +[OFString stringWithContentsOfFile:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cc34255955421dac47035c5a817ca830831432bc149a9955bb43722602ce55af
User & Date: js on 2010-11-17 22:31:17
Other Links: manifest | tags
Context
2010-11-17
22:35
Add -[parseString:] and -[parseFile:] to OFXMLParser. check-in: 08fcb79a9b user: js tags: trunk
22:31
Close file on exception in +[OFString stringWithContentsOfFile:]. check-in: cc34255955 user: js tags: trunk
20:35
Remove now unnecessary safety check from -[componentsJoinedByString]. check-in: e4f8d0a4e9 user: js tags: trunk
Changes

Modified src/OFString.m from [408783a5f8] to [93873903ed].

615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633




634
635
636
637
638
639
640
641


642
643
644
645
646
647
648
649
650

- initWithContentsOfFile: (OFString*)path
		encoding: (enum of_string_encoding)encoding
{
	self = [super init];

	@try {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
		OFFile *file;
		char *tmp;
		struct stat s;

		if (stat([path cString], &s) == -1)
			@throw [OFInitializationFailedException
			    newWithClass: isa];

		tmp = [self allocMemoryWithSize: s.st_size];
		file = [OFFile fileWithPath: path
				       mode: @"rb"];




		[file readExactlyNBytes: s.st_size
			     intoBuffer: tmp];

		self = [self initWithCString: tmp
				    encoding: encoding
				      length: s.st_size];

		[self freeMemory: tmp];



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

	return self;
}







<








<
|
|
>
>
>
>
|
|

|
|
|

|
>
>
|
<







615
616
617
618
619
620
621

622
623
624
625
626
627
628
629

630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646

647
648
649
650
651
652
653

- initWithContentsOfFile: (OFString*)path
		encoding: (enum of_string_encoding)encoding
{
	self = [super init];

	@try {

		OFFile *file;
		char *tmp;
		struct stat s;

		if (stat([path cString], &s) == -1)
			@throw [OFInitializationFailedException
			    newWithClass: isa];


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

		@try {
			tmp = [self allocMemoryWithSize: s.st_size];

			[file readExactlyNBytes: s.st_size
				     intoBuffer: tmp];

			self = [self initWithCString: tmp
					    encoding: encoding
					      length: s.st_size];

			[self freeMemory: tmp];
		} @finally {
			[file release];
		}

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

	return self;
}