ObjFW  Check-in [4ebeb7e3a2]

Overview
Comment:Make of_(l)stat() private to OFFileManager

Everything else should just use OFFileManager.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4ebeb7e3a20328267f212bed182b6a36e861a0de9aef0123d09ae3bb6035056b
User & Date: js on 2017-06-03 12:46:40
Other Links: manifest | tags
Context
2017-06-03
14:37
OFFileManager: Mask modes to ensure safe modes check-in: 4175b93242 user: js tags: trunk
12:46
Make of_(l)stat() private to OFFileManager check-in: 4ebeb7e3a2 user: js tags: trunk
2017-05-30
22:01
MorphOS: Name variable handle instead of fd check-in: c5c3df3abe user: js tags: trunk
Changes

Modified src/OFFile.h from [0b74319ed1] to [770e6d77e6].

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
 *
 * 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.
 */

#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS
#endif
#ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS
#endif

#include <sys/types.h>
#include <sys/stat.h>

#import "OFSeekableStream.h"

OF_ASSUME_NONNULL_BEGIN

#if defined(OF_WINDOWS)
typedef struct __stat64 of_stat_t;
#elif defined(OF_HAVE_OFF64_T)
typedef struct stat64 of_stat_t;
#else
typedef struct stat of_stat_t;
#endif

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
typedef long BPTR;
#endif

/*!
 * @class OFFile OFFile.h ObjFW/OFFile.h
 *







<
<
<
<
<
<
<
<
<
<




<
<
<
<
<
<
<
<







10
11
12
13
14
15
16










17
18
19
20








21
22
23
24
25
26
27
 *
 * 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 "OFSeekableStream.h"

OF_ASSUME_NONNULL_BEGIN









#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
typedef long BPTR;
#endif

/*!
 * @class OFFile OFFile.h ObjFW/OFFile.h
 *
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
 *		 It is closed when the OFFile object is deallocated!
 * @return An initialized OFFile
 */
- initWithHandle: (BPTR)handle;
#endif
@end

#ifdef __cplusplus
extern "C" {
#endif
extern int of_stat(OFString *path, of_stat_t *buffer);
extern int of_lstat(OFString *path, of_stat_t *buffer);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END







<
<
<
<
<
<
<
<
<

127
128
129
130
131
132
133









134
 *		 It is closed when the OFFile object is deallocated!
 * @return An initialized OFFile
 */
- initWithHandle: (BPTR)handle;
#endif
@end










OF_ASSUME_NONNULL_END

Modified src/OFFileManager.h from [89d56ff83d] to [9bf42c8f55].

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 * 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"
#import "OFFile.h"

OF_ASSUME_NONNULL_BEGIN

@class OFArray OF_GENERIC(ObjectType);
@class OFDate;

/*!







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 * 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"
#import "OFSeekableStream.h"

OF_ASSUME_NONNULL_BEGIN

@class OFArray OF_GENERIC(ObjectType);
@class OFDate;

/*!

Modified src/OFFileManager.m from [6281bc6839] to [4b4f8f0aeb].

18
19
20
21
22
23
24




25
26
27
28
29
30
31

#include <errno.h>

#ifdef HAVE_DIRENT_H
# include <dirent.h>
#endif
#include "unistd_wrapper.h"





#ifdef HAVE_PWD_H
# include <pwd.h>
#endif
#ifdef HAVE_GRP_H
# include <grp.h>
#endif







>
>
>
>







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

#include <errno.h>

#ifdef HAVE_DIRENT_H
# include <dirent.h>
#endif
#include "unistd_wrapper.h"

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

#ifdef HAVE_PWD_H
# include <pwd.h>
#endif
#ifdef HAVE_GRP_H
# include <grp.h>
#endif
78
79
80
81
82
83
84








85
86
87
88
89
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
119
120
#endif
#ifndef S_IWOTH
# define S_IWOTH 0
#endif

#define DEFAULT_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
#define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH









static OFFileManager *defaultManager;

#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
static OFMutex *passwdMutex;
#endif
#if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS)
static OFMutex *readdirMutex;
#endif

#ifdef OF_WINDOWS
static WINAPI BOOLEAN (*func_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD);
#endif

int
of_stat(OFString *path, of_stat_t *buffer)
{
#if defined(OF_WINDOWS)
	return _wstat64([path UTF16String], buffer);
#elif defined(OF_HAVE_OFF64_T)
	return stat64([path cStringWithEncoding: [OFLocalization encoding]],
	    buffer);
#else
	return stat([path cStringWithEncoding: [OFLocalization encoding]],
	    buffer);
#endif
}

int
of_lstat(OFString *path, of_stat_t *buffer)
{
#if defined(OF_WINDOWS)
	return _wstat64([path UTF16String], buffer);
#elif defined(HAVE_LSTAT)
# ifdef OF_HAVE_OFF64_T
	return lstat64([path cStringWithEncoding: [OFLocalization encoding]],







>
>
>
>
>
>
>
>














|













|







82
83
84
85
86
87
88
89
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#endif
#ifndef S_IWOTH
# define S_IWOTH 0
#endif

#define DEFAULT_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
#define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH

#if defined(OF_WINDOWS)
typedef struct __stat64 of_stat_t;
#elif defined(OF_HAVE_OFF64_T)
typedef struct stat64 of_stat_t;
#else
typedef struct stat of_stat_t;
#endif

static OFFileManager *defaultManager;

#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
static OFMutex *passwdMutex;
#endif
#if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS)
static OFMutex *readdirMutex;
#endif

#ifdef OF_WINDOWS
static WINAPI BOOLEAN (*func_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD);
#endif

static int
of_stat(OFString *path, of_stat_t *buffer)
{
#if defined(OF_WINDOWS)
	return _wstat64([path UTF16String], buffer);
#elif defined(OF_HAVE_OFF64_T)
	return stat64([path cStringWithEncoding: [OFLocalization encoding]],
	    buffer);
#else
	return stat([path cStringWithEncoding: [OFLocalization encoding]],
	    buffer);
#endif
}

static int
of_lstat(OFString *path, of_stat_t *buffer)
{
#if defined(OF_WINDOWS)
	return _wstat64([path UTF16String], buffer);
#elif defined(HAVE_LSTAT)
# ifdef OF_HAVE_OFF64_T
	return lstat64([path cStringWithEncoding: [OFLocalization encoding]],

Modified src/OFString.m from [fd491800a0] to [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
#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"

#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 "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"

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

/*







<
<
<
<









>




















>







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





#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
				   encoding: OF_STRING_ENCODING_UTF_8];
}

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

	@try {
		OFFile *file;

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

		if (of_stat(path, &st) != 0)
			@throw [OFOpenItemFailedException
			    exceptionWithPath: path
					 mode: @"rb"
					errNo: errno];


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

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

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

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

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

	return self;
}
#endif

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







|




|
|
|
|




|
>

|






|


|










|







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_offset_t fileSize;

	@try {
		OFFile *file;

		@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) &&
		    fileSize > (of_offset_t)SIZE_MAX)
			@throw [OFOutOfRangeException exception];

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

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

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

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

	return self;
}
#endif

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

Modified utils/ofzip/OFZIP.h from [13ab30e52b] to [586c99b15f].

10
11
12
13
14
15
16

17

18
19
20
21
22
23
24
 *
 * 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 <sys/stat.h>


#import "OFObject.h"
#import "OFString.h"

#import "Archive.h"

#ifndef S_IRWXG







>
|
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * 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.
 */

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

#import "OFObject.h"
#import "OFString.h"

#import "Archive.h"

#ifndef S_IRWXG