ObjFW  Diff

Differences From Artifact [e0dd905710]:

To Artifact [52d4d85f15]:

  • File src/OFString.m — part of check-in [62e2de30b9] at 2015-02-16 08:39:17 on branch trunk — Explicitly pass errno to exceptions

    The old behaviour where the exception would access errno directly on
    creation of the exception was very fragile. The two main problems with
    it were that sometimes it would pick up an errno even though none had
    been set and in other cases that when the exception was created errno
    had already been overridden.

    This also greatly increases errno handling on Win32, especially in
    conjunction with sockets. It can still be improved further, though. (user: js, size: 55971) [annotate] [blame] [check-ins using]


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
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







+
+



-









-







 * 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"

#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include <sys/stat.h>

#import "OFString.h"
#import "OFString_UTF8.h"
#import "OFString_UTF8+Private.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFDataArray.h"
#import "OFSystemInfo.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif
#import "OFURL.h"
#ifdef OF_HAVE_SOCKETS
# import "OFHTTPClient.h"
# import "OFHTTPRequest.h"
817
818
819
820
821
822
823
824

825
826
827
828
829
830
831
832
833

834
835
836


837
838
839
840
841
842
843
817
818
819
820
821
822
823

824
825
826
827
828
829
830
831


832
833
834

835
836
837
838
839
840
841
842
843







-
+







-
-
+


-
+
+







				   encoding: OF_STRING_ENCODING_UTF_8];
}

- initWithContentsOfFile: (OFString*)path
		encoding: (of_string_encoding_t)encoding
{
	char *tmp;
	struct stat st;
	of_stat_t st;

	@try {
		OFFile *file;

		/* Make sure the file system is initialized */
		[OFFile class];

		if (stat([path cStringWithEncoding:
		    [OFSystemInfo native8BitEncoding]], &st) == -1)
		if (of_stat(path, &st) != 0)
			@throw [OFOpenFileFailedException
			    exceptionWithPath: path
					 mode: @"rb"];
					 mode: @"rb"
					errNo: errno];

		if (st.st_size > SIZE_MAX)
			@throw [OFOutOfRangeException exception];

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