ObjFW  Diff

Differences From Artifact [fd491800a0]:

To Artifact [094992d7f8]:


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







-
-
-
-









+




















+







#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L)
# include <locale.h>
#endif
#ifdef HAVE_XLOCALE_H
# include <xlocale.h>
#endif

#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif

#import "OFString.h"
#import "OFString_UTF8.h"
#import "OFString_UTF8+Private.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFDataArray.h"
#import "OFLocalization.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
# import "OFFileManager.h"
#endif
#import "OFURL.h"
#ifdef OF_HAVE_SOCKETS
# import "OFHTTPClient.h"
# import "OFHTTPRequest.h"
# import "OFHTTPResponse.h"
#endif
#import "OFXMLElement.h"

#ifdef OF_HAVE_SOCKETS
# import "OFHTTPRequestFailedException.h"
#endif
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFStatItemFailedException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"

#import "of_asprintf.h"
#import "unicode.h"

/*
921
922
923
924
925
926
927
928

929
930
931
932
933
934
935
936




937
938
939
940
941


942
943

944
945
946
947
948
949
950

951
952
953

954
955
956
957
958
959
960
961
962
963
964

965
966
967
968
969
970
971
919
920
921
922
923
924
925

926
927
928
929
930




931
932
933
934
935
936
937
938

939
940
941

942
943
944
945
946
947
948

949
950
951

952
953
954
955
956
957
958
959
960
961
962

963
964
965
966
967
968
969
970







-
+




-
-
-
-
+
+
+
+




-
+
+

-
+






-
+


-
+










-
+







				   encoding: OF_STRING_ENCODING_UTF_8];
}

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

	@try {
		OFFile *file;

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

		if (of_stat(path, &st) != 0)
		@try {
			fileSize = [[OFFileManager defaultManager]
			    sizeOfFileAtPath: path];
		} @catch (OFStatItemFailedException *e) {
			@throw [OFOpenItemFailedException
			    exceptionWithPath: path
					 mode: @"rb"
					errNo: errno];

		}

		if (sizeof(of_offset_t) > sizeof(size_t) &&
		    st.st_size > (of_offset_t)SIZE_MAX)
		    fileSize > (of_offset_t)SIZE_MAX)
			@throw [OFOutOfRangeException exception];

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

		@try {
			tmp = [self allocMemoryWithSize: (size_t)st.st_size];
			tmp = [self allocMemoryWithSize: (size_t)fileSize];

			[file readIntoBuffer: tmp
				 exactLength: (size_t)st.st_size];
				 exactLength: (size_t)fileSize];
		} @finally {
			[file release];
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithCString: tmp
			    encoding: encoding
			      length: (size_t)st.st_size];
			      length: (size_t)fileSize];
	[self freeMemory: tmp];

	return self;
}
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)