ObjFW  Check-in [c9621825fc]

Overview
Comment:Treat MorphOS + ixemul as a separate platform

This reduces the ifdef hell and makes much more sense, as with ixemul,
no native calls are allowed.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c9621825fc5b1ebf67941b3bb76ed166fcd56ec47a5d9f6d26146fa06f8d905f
User & Date: js on 2017-06-04 18:48:03
Other Links: manifest | tags
Context
2017-06-04
23:41
Add designated initializer to all exceptions check-in: cc5923d6bb user: js tags: trunk
18:48
Treat MorphOS + ixemul as a separate platform check-in: c9621825fc user: js tags: trunk
18:16
OFFile: Make sure to not leak handles on MorphOS check-in: 1ffd8f9f16 user: js tags: trunk
Changes

Modified src/OFApplication.m from [cd6046dfba] to [970d1b40a3].

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
#import "OFDictionary.h"
#import "OFLocalization.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFThread.h"
#import "OFThread+Private.h"
#import "OFSandbox.h"
#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
# import "OFFile.h"
# import "OFFileManager.h"
#endif

#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFSandboxActivationFailedException.h"

#if defined(OF_MACOS)
# include <crt_externs.h>
#elif defined(OF_WINDOWS)
# include <windows.h>

extern int _CRT_glob;
extern void __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *);
#elif defined(OF_MORPHOS) && !defined(OF_IXEMUL)
# define BOOL EXEC_BOOL
# include <proto/exec.h>
# include <proto/dos.h>
# undef BOOL
#elif !defined(OF_IOS)
extern char **environ;
#endif







|















|







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
#import "OFDictionary.h"
#import "OFLocalization.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFThread.h"
#import "OFThread+Private.h"
#import "OFSandbox.h"
#ifdef OF_MORPHOS
# import "OFFile.h"
# import "OFFileManager.h"
#endif

#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFSandboxActivationFailedException.h"

#if defined(OF_MACOS)
# include <crt_externs.h>
#elif defined(OF_WINDOWS)
# include <windows.h>

extern int _CRT_glob;
extern void __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *);
#elif defined(OF_MORPHOS)
# define BOOL EXEC_BOOL
# include <proto/exec.h>
# include <proto/dos.h>
# undef BOOL
#elif !defined(OF_IOS)
extern char **environ;
#endif
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
			[_environment setObject: value
					 forKey: key];

			objc_autoreleasePoolPop(pool);
		}

		FreeEnvironmentStringsW(env0);
#elif defined(OF_MORPHOS) && !defined(OF_IXEMUL)
		void *pool = objc_autoreleasePoolPush();
		OFFileManager *fileManager = [OFFileManager defaultManager];
		OFArray *envContents =
		    [fileManager contentsOfDirectoryAtPath: @"ENV:"];
		const of_string_encoding_t encoding = [OFLocalization encoding];
		struct Process *proc;
		struct LocalVar *firstLocalVar;







|







263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
			[_environment setObject: value
					 forKey: key];

			objc_autoreleasePoolPop(pool);
		}

		FreeEnvironmentStringsW(env0);
#elif defined(OF_MORPHOS)
		void *pool = objc_autoreleasePoolPush();
		OFFileManager *fileManager = [OFFileManager defaultManager];
		OFArray *envContents =
		    [fileManager contentsOfDirectoryAtPath: @"ENV:"];
		const of_string_encoding_t encoding = [OFLocalization encoding];
		struct Process *proc;
		struct LocalVar *firstLocalVar;

Modified src/OFFile.h from [60494c4dc6] to [dcb097e34e].

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

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
# define OF_FILE_HANDLE_IS_FD
# define OF_INVALID_FILE_HANDLE (-1)
# define OF_FILE_HANDLE_IS_VALID(h) (h != -1)
typedef int of_file_handle_t;
#else
# define BOOL EXEC_BOOL
# include <proto/dos.h>







|







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

#ifndef OF_MORPHOS
# define OF_FILE_HANDLE_IS_FD
# define OF_INVALID_FILE_HANDLE (-1)
# define OF_FILE_HANDLE_IS_VALID(h) (h != -1)
typedef int of_file_handle_t;
#else
# define BOOL EXEC_BOOL
# include <proto/dos.h>

Modified src/OFFile.m from [9167fd4ad1] to [4cea821d7a].

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef O_EXCL
# define O_EXCL 0
#endif
#ifndef O_EXLOCK
# define O_EXLOCK 0
#endif

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
# define closeHandle(h) close(h)
#else
static OFDataArray *openHandles = nil;

static void
closeHandle(of_file_handle_t handle)
{







|







65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef O_EXCL
# define O_EXCL 0
#endif
#ifndef O_EXLOCK
# define O_EXLOCK 0
#endif

#ifndef OF_MORPHOS
# define closeHandle(h) close(h)
#else
static OFDataArray *openHandles = nil;

static void
closeHandle(of_file_handle_t handle)
{
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
	size_t count = [openHandles count];

	for (size_t i = 0; i < count; i++)
		Close(handles[i]);
}
#endif

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
static int
parseMode(const char *mode)
{
	if (strcmp(mode, "r") == 0)
		return O_RDONLY;
	if (strcmp(mode, "w") == 0)
		return O_WRONLY | O_CREAT | O_TRUNC;







|







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
	size_t count = [openHandles count];

	for (size_t i = 0; i < count; i++)
		Close(handles[i]);
}
#endif

#ifndef OF_MORPHOS
static int
parseMode(const char *mode)
{
	if (strcmp(mode, "r") == 0)
		return O_RDONLY;
	if (strcmp(mode, "w") == 0)
		return O_WRONLY | O_CREAT | O_TRUNC;
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

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

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
	openHandles = [[OFDataArray alloc] initWithItemSize: sizeof(BPTR)];
#endif

#ifdef OF_WII
	if (!fatInitDefault())
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];







|







188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

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

#ifdef OF_MORPHOS
	openHandles = [[OFDataArray alloc] initWithItemSize: sizeof(BPTR)];
#endif

#ifdef OF_WII
	if (!fatInitDefault())
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
{
	of_file_handle_t handle;

	@try {
		void *pool = objc_autoreleasePoolPush();
		int flags;

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
		if ((flags = parseMode([mode UTF8String])) == -1)
			@throw [OFInvalidArgumentException exception];

		flags |= O_CLOEXEC;

# if defined(OF_WINDOWS)
		if ((handle = _wopen([path UTF16String], flags,







|







231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
{
	of_file_handle_t handle;

	@try {
		void *pool = objc_autoreleasePoolPush();
		int flags;

#ifndef OF_MORPHOS
		if ((flags = parseMode([mode UTF8String])) == -1)
			@throw [OFInvalidArgumentException exception];

		flags |= O_CLOEXEC;

# if defined(OF_WINDOWS)
		if ((handle = _wopen([path UTF16String], flags,
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
	if (length > UINT_MAX)
		@throw [OFOutOfRangeException exception];

	if ((ret = read(_handle, buffer, (unsigned int)length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length
							    errNo: errno];
#elif defined(OF_MORPHOS) && !defined(OF_IXEMUL)
	if (length > LONG_MAX)
		@throw [OFOutOfRangeException exception];

	if ((ret = Read(_handle.handle, buffer, length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length];
#else







|







327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
	if (length > UINT_MAX)
		@throw [OFOutOfRangeException exception];

	if ((ret = read(_handle, buffer, (unsigned int)length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length
							    errNo: errno];
#elif defined(OF_MORPHOS)
	if (length > LONG_MAX)
		@throw [OFOutOfRangeException exception];

	if ((ret = Read(_handle.handle, buffer, length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length];
#else
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
	if (length > INT_MAX)
		@throw [OFOutOfRangeException exception];

	if (write(_handle, buffer, (int)length) != (int)length)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length
							     errNo: errno];
#elif defined(OF_MORPHOS) && !defined(OF_IXEMUL)
	if (length > LONG_MAX)
		@throw [OFOutOfRangeException exception];

	if (_handle.append) {
		if (Seek64(_handle.handle, 0, OFFSET_END) == -1)
			@throw [OFWriteFailedException
			    exceptionWithObject: self







|







362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
	if (length > INT_MAX)
		@throw [OFOutOfRangeException exception];

	if (write(_handle, buffer, (int)length) != (int)length)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length
							     errNo: errno];
#elif defined(OF_MORPHOS)
	if (length > LONG_MAX)
		@throw [OFOutOfRangeException exception];

	if (_handle.append) {
		if (Seek64(_handle.handle, 0, OFFSET_END) == -1)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
	of_offset_t ret;

	if (!OF_FILE_HANDLE_IS_VALID(_handle))
		@throw [OFSeekFailedException exceptionWithStream: self
							   offset: offset
							   whence: whence];

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
# if defined(OF_WINDOWS)
	ret = _lseeki64(_handle, offset, whence);
# elif defined(OF_HAVE_OFF64_T)
	ret = lseek64(_handle, offset, whence);
# else
	ret = lseek(_handle, offset, whence);
# endif







|







397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
	of_offset_t ret;

	if (!OF_FILE_HANDLE_IS_VALID(_handle))
		@throw [OFSeekFailedException exceptionWithStream: self
							   offset: offset
							   whence: whence];

#ifndef OF_MORPHOS
# if defined(OF_WINDOWS)
	ret = _lseeki64(_handle, offset, whence);
# elif defined(OF_HAVE_OFF64_T)
	ret = lseek64(_handle, offset, whence);
# else
	ret = lseek(_handle, offset, whence);
# endif

Modified src/OFLocalization.m from [c0aec31b97] to [1e6c9574a4].

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
# define BOOL EXEC_BOOL
# include <proto/dos.h>
# include <proto/locale.h>
# undef BOOL
#endif

static OFLocalization *sharedLocalization = nil;

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
static void
parseLocale(char *locale, of_string_encoding_t *encoding,
    OFString **language, OFString **territory)
{
	if ((locale = of_strdup(locale)) == NULL)
		return;








|








|







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"

#ifdef OF_MORPHOS
# define BOOL EXEC_BOOL
# include <proto/dos.h>
# include <proto/locale.h>
# undef BOOL
#endif

static OFLocalization *sharedLocalization = nil;

#ifndef OF_MORPHOS
static void
parseLocale(char *locale, of_string_encoding_t *encoding,
    OFString **language, OFString **territory)
{
	if ((locale = of_strdup(locale)) == NULL)
		return;

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#endif

- init
{
	self = [super init];

	@try {
#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
		char *locale, *messagesLocale = NULL;

		_encoding = OF_STRING_ENCODING_UTF_8;
		_decimalPoint = @".";
		_localizedStrings = [[OFMutableArray alloc] init];

		if ((locale = setlocale(LC_ALL, "")) != NULL)







|







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#endif

- init
{
	self = [super init];

	@try {
#ifndef OF_MORPHOS
		char *locale, *messagesLocale = NULL;

		_encoding = OF_STRING_ENCODING_UTF_8;
		_decimalPoint = @".";
		_localizedStrings = [[OFMutableArray alloc] init];

		if ((locale = setlocale(LC_ALL, "")) != NULL)

Modified src/OFSeekableStream.h from [6b187920bd] to [5ba9582e3e].

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

OF_ASSUME_NONNULL_BEGIN

#if defined(OF_WINDOWS)
typedef __int64 of_offset_t;
#elif defined(OF_ANDROID)
typedef long long of_offset_t;
#elif defined(OF_MORPHOS) && !defined(OF_IXEMUL)
typedef signed long long of_offset_t;
#elif defined(OF_HAVE_OFF64_T)
typedef off64_t of_offset_t;
#else
typedef off_t of_offset_t;
#endif








|







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

OF_ASSUME_NONNULL_BEGIN

#if defined(OF_WINDOWS)
typedef __int64 of_offset_t;
#elif defined(OF_ANDROID)
typedef long long of_offset_t;
#elif defined(OF_MORPHOS)
typedef signed long long of_offset_t;
#elif defined(OF_HAVE_OFF64_T)
typedef off64_t of_offset_t;
#else
typedef off_t of_offset_t;
#endif

Modified src/OFStdIOStream+Private.h from [f4f520c039] to [7ad2e58776].

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

#import "OFStdIOStream.h"

OF_ASSUME_NONNULL_BEGIN

@interface OFStdIOStream ()
#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
- (instancetype)of_initWithFileDescriptor: (int)fd OF_METHOD_FAMILY(init);
#else
- (instancetype)of_initWithHandle: (BPTR)handle
			 closable: (bool)closable OF_METHOD_FAMILY(init);
#endif
@end

OF_ASSUME_NONNULL_END







|








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

#import "OFStdIOStream.h"

OF_ASSUME_NONNULL_BEGIN

@interface OFStdIOStream ()
#ifndef OF_MORPHOS
- (instancetype)of_initWithFileDescriptor: (int)fd OF_METHOD_FAMILY(init);
#else
- (instancetype)of_initWithHandle: (BPTR)handle
			 closable: (bool)closable OF_METHOD_FAMILY(init);
#endif
@end

OF_ASSUME_NONNULL_END

Modified src/OFStdIOStream.h from [5eecd0463f] to [791f773daf].

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
 * 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 "OFStream.h"

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
# define BOOL EXEC_BOOL
# include <proto/dos.h>
# undef BOOL
#endif

OF_ASSUME_NONNULL_BEGIN

/*!
 * @class OFStdIOStream OFStdIOStream.h ObjFW/OFStdIOStream.h
 *
 * @brief A class for providing standard input, output and error as OFStream.
 *
 * The global variables @ref of_stdin, @ref of_stdout and @ref of_stderr are
 * instances of this class and need no initialization.
 */
#ifdef OF_STDIO_STREAM_WIN32_CONSOLE_H
OF_SUBCLASSING_RESTRICTED
#endif
@interface OFStdIOStream: OFStream
{
#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	int _fd;
#else
	BPTR _handle;
	bool _closable;
#endif
	bool _atEndOfStream;
}







|




















|







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
 * 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 "OFStream.h"

#ifdef OF_MORPHOS
# define BOOL EXEC_BOOL
# include <proto/dos.h>
# undef BOOL
#endif

OF_ASSUME_NONNULL_BEGIN

/*!
 * @class OFStdIOStream OFStdIOStream.h ObjFW/OFStdIOStream.h
 *
 * @brief A class for providing standard input, output and error as OFStream.
 *
 * The global variables @ref of_stdin, @ref of_stdout and @ref of_stderr are
 * instances of this class and need no initialization.
 */
#ifdef OF_STDIO_STREAM_WIN32_CONSOLE_H
OF_SUBCLASSING_RESTRICTED
#endif
@interface OFStdIOStream: OFStream
{
#ifndef OF_MORPHOS
	int _fd;
#else
	BPTR _handle;
	bool _closable;
#endif
	bool _atEndOfStream;
}

Modified src/OFStdIOStream.m from [ac607c5f45] to [87d19ba681].

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
# include "OFStdIOStream_Win32Console.h"
#endif

#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
# define BOOL EXEC_BOOL
# include <proto/exec.h>
# undef BOOL
#endif

/* References for static linking */
#ifdef OF_WINDOWS
void
_reference_to_OFStdIOStream_Win32Console(void)
{
	[OFStdIOStream_Win32Console class];
}
#endif

OFStdIOStream *of_stdin = nil;
OFStdIOStream *of_stdout = nil;
OFStdIOStream *of_stderr = nil;

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
OF_DESTRUCTOR()
{
	[of_stdin dealloc];
	[of_stdout dealloc];
	[of_stderr dealloc];
}
#endif







|


















|







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
# include "OFStdIOStream_Win32Console.h"
#endif

#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#ifdef OF_MORPHOS
# define BOOL EXEC_BOOL
# include <proto/exec.h>
# undef BOOL
#endif

/* References for static linking */
#ifdef OF_WINDOWS
void
_reference_to_OFStdIOStream_Win32Console(void)
{
	[OFStdIOStream_Win32Console class];
}
#endif

OFStdIOStream *of_stdin = nil;
OFStdIOStream *of_stdout = nil;
OFStdIOStream *of_stderr = nil;

#ifdef OF_MORPHOS
OF_DESTRUCTOR()
{
	[of_stdin dealloc];
	[of_stdout dealloc];
	[of_stderr dealloc];
}
#endif
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	objc_autoreleasePoolPop(pool);
}

@implementation OFStdIOStream
#ifndef OF_WINDOWS
+ (void)load
{
# if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	of_stdin = [[OFStdIOStream alloc] of_initWithFileDescriptor: 0];
	of_stdout = [[OFStdIOStream alloc] of_initWithFileDescriptor: 1];
	of_stderr = [[OFStdIOStream alloc] of_initWithFileDescriptor: 2];
# else
	BPTR input = Input(), output = Output();
	BPTR error = ((struct Process *)FindTask(NULL))->pr_CES;
	bool inputClosable = false, outputClosable = false,







|







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	objc_autoreleasePoolPop(pool);
}

@implementation OFStdIOStream
#ifndef OF_WINDOWS
+ (void)load
{
# ifndef OF_MORPHOS
	of_stdin = [[OFStdIOStream alloc] of_initWithFileDescriptor: 0];
	of_stdout = [[OFStdIOStream alloc] of_initWithFileDescriptor: 1];
	of_stderr = [[OFStdIOStream alloc] of_initWithFileDescriptor: 2];
# else
	BPTR input = Input(), output = Output();
	BPTR error = ((struct Process *)FindTask(NULL))->pr_CES;
	bool inputClosable = false, outputClosable = false,
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#endif

- init
{
	OF_INVALID_INIT_METHOD
}

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
- (instancetype)of_initWithFileDescriptor: (int)fd
{
	self = [super init];

	_fd = fd;

	return self;







|







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#endif

- init
{
	OF_INVALID_INIT_METHOD
}

#ifndef OF_MORPHOS
- (instancetype)of_initWithFileDescriptor: (int)fd
{
	self = [super init];

	_fd = fd;

	return self;
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
	[self close];

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	if (_fd == -1)
		return true;
#else
	if (_handle == 0)
		return true;
#endif

	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
			  length: (size_t)length
{
	ssize_t ret;

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	if (_fd == -1 || _atEndOfStream)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length];

# ifndef OF_WINDOWS
	if ((ret = read(_fd, buffer, length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self







|















|







161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
	[self close];

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
#ifndef OF_MORPHOS
	if (_fd == -1)
		return true;
#else
	if (_handle == 0)
		return true;
#endif

	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
			  length: (size_t)length
{
	ssize_t ret;

#ifndef OF_MORPHOS
	if (_fd == -1 || _atEndOfStream)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length];

# ifndef OF_WINDOWS
	if ((ret = read(_fd, buffer, length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

	return ret;
}

- (void)lowlevelWriteBuffer: (const void *)buffer
		     length: (size_t)length
{
#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	if (_fd == -1 || _atEndOfStream)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length];

# ifndef OF_WINDOWS
	if (length > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];







|







218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

	return ret;
}

- (void)lowlevelWriteBuffer: (const void *)buffer
		     length: (size_t)length
{
#ifndef OF_MORPHOS
	if (_fd == -1 || _atEndOfStream)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length];

# ifndef OF_WINDOWS
	if (length > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];
254
255
256
257
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

	if (Write(_handle, (void *)buffer, length) != (LONG)length)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length];
#endif
}

#if !defined(OF_WINDOWS) && (!defined(OF_MORPHOS) || defined(OF_IXEMUL))
- (int)fileDescriptorForReading
{
	return _fd;
}

- (int)fileDescriptorForWriting
{
	return _fd;
}
#endif

- (void)close
{
#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	if (_fd != -1)
		close(_fd);

	_fd = -1;
#else
	if (_closable && _handle != 0)
		Close(_handle);







|













|







254
255
256
257
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

	if (Write(_handle, (void *)buffer, length) != (LONG)length)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length];
#endif
}

#if !defined(OF_WINDOWS) && !defined(OF_MORPHOS)
- (int)fileDescriptorForReading
{
	return _fd;
}

- (int)fileDescriptorForWriting
{
	return _fd;
}
#endif

- (void)close
{
#ifndef OF_MORPHOS
	if (_fd != -1)
		close(_fd);

	_fd = -1;
#else
	if (_closable && _handle != 0)
		Close(_handle);
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
- (unsigned int)retainCount
{
	return OF_RETAIN_COUNT_MAX;
}

- (int)columns
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && \
    (!defined(OF_MORPHOS) || defined(OF_IXEMUL))
	struct winsize ws;

	if (ioctl(_fd, TIOCGWINSZ, &ws) != 0)
		return -1;

	return ws.ws_col;
#else
	return -1;
#endif
}

- (int)rows
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && \
    (!defined(OF_MORPHOS) || defined(OF_IXEMUL))
	struct winsize ws;

	if (ioctl(_fd, TIOCGWINSZ, &ws) != 0)
		return -1;

	return ws.ws_row;
#else
	return -1;
#endif
}
@end







|
<













|
<











304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325

326
327
328
329
330
331
332
333
334
335
336
- (unsigned int)retainCount
{
	return OF_RETAIN_COUNT_MAX;
}

- (int)columns
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_MORPHOS)

	struct winsize ws;

	if (ioctl(_fd, TIOCGWINSZ, &ws) != 0)
		return -1;

	return ws.ws_col;
#else
	return -1;
#endif
}

- (int)rows
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_MORPHOS)

	struct winsize ws;

	if (ioctl(_fd, TIOCGWINSZ, &ws) != 0)
		return -1;

	return ws.ws_row;
#else
	return -1;
#endif
}
@end

Modified src/OFStream.m from [c3c3a5a8ae] to [ffb5628418].

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

#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif

#include "platform.h"

#if !defined(OF_WINDOWS) && (!defined(OF_MORPHOS) || defined(OF_IXEMUL))
# include <signal.h>
#endif

#import "OFStream.h"
#import "OFStream+Private.h"
#import "OFString.h"
#import "OFDataArray.h"







|







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

#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif

#include "platform.h"

#if !defined(OF_WINDOWS) && !defined(OF_MORPHOS)
# include <signal.h>
#endif

#import "OFStream.h"
#import "OFStream+Private.h"
#import "OFString.h"
#import "OFDataArray.h"
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#import "of_asprintf.h"

#define MIN_READ_SIZE 512

@implementation OFStream
@synthesize of_waitingForDelimiter = _waitingForDelimiter;

#if !defined(OF_WINDOWS) && (!defined(OF_MORPHOS) || defined(OF_IXEMUL))
+ (void)initialize
{
	if (self == [OFStream class])
		signal(SIGPIPE, SIG_IGN);
}
#endif








|







52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#import "of_asprintf.h"

#define MIN_READ_SIZE 512

@implementation OFStream
@synthesize of_waitingForDelimiter = _waitingForDelimiter;

#if !defined(OF_WINDOWS) && !defined(OF_MORPHOS)
+ (void)initialize
{
	if (self == [OFStream class])
		signal(SIGPIPE, SIG_IGN);
}
#endif

Modified src/OFString.m from [41447adc66] to [51b9feaad9].

2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
	return value;
}

- (float)floatValue
{
	void *pool = objc_autoreleasePoolPush();

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
	OFString *stripped = [self stringByDeletingEnclosingWhitespaces];

	if ([stripped caseInsensitiveCompare: @"INF"] == OF_ORDERED_SAME ||
	    [stripped caseInsensitiveCompare: @"INFINITY"] == OF_ORDERED_SAME)
		return INFINITY;
	if ([stripped caseInsensitiveCompare: @"-INF"] == OF_ORDERED_SAME ||
	    [stripped caseInsensitiveCompare: @"-INFINITY"] == OF_ORDERED_SAME)







|







2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
	return value;
}

- (float)floatValue
{
	void *pool = objc_autoreleasePoolPush();

#ifdef OF_MORPHOS
	OFString *stripped = [self stringByDeletingEnclosingWhitespaces];

	if ([stripped caseInsensitiveCompare: @"INF"] == OF_ORDERED_SAME ||
	    [stripped caseInsensitiveCompare: @"INFINITY"] == OF_ORDERED_SAME)
		return INFINITY;
	if ([stripped caseInsensitiveCompare: @"-INF"] == OF_ORDERED_SAME ||
	    [stripped caseInsensitiveCompare: @"-INFINITY"] == OF_ORDERED_SAME)
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
	return value;
}

- (double)doubleValue
{
	void *pool = objc_autoreleasePoolPush();

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
	OFString *stripped = [self stringByDeletingEnclosingWhitespaces];

	if ([stripped caseInsensitiveCompare: @"INF"] == OF_ORDERED_SAME ||
	    [stripped caseInsensitiveCompare: @"INFINITY"] == OF_ORDERED_SAME)
		return INFINITY;
	if ([stripped caseInsensitiveCompare: @"-INF"] == OF_ORDERED_SAME ||
	    [stripped caseInsensitiveCompare: @"-INFINITY"] == OF_ORDERED_SAME)







|







2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
	return value;
}

- (double)doubleValue
{
	void *pool = objc_autoreleasePoolPush();

#ifdef OF_MORPHOS
	OFString *stripped = [self stringByDeletingEnclosingWhitespaces];

	if ([stripped caseInsensitiveCompare: @"INF"] == OF_ORDERED_SAME ||
	    [stripped caseInsensitiveCompare: @"INFINITY"] == OF_ORDERED_SAME)
		return INFINITY;
	if ([stripped caseInsensitiveCompare: @"-INF"] == OF_ORDERED_SAME ||
	    [stripped caseInsensitiveCompare: @"-INFINITY"] == OF_ORDERED_SAME)

Modified src/OFThread.m from [27186ac8aa] to [3ff1e2b592].

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifdef OF_HAVE_SCHED_YIELD
# include <sched.h>
#endif
#include "unistd_wrapper.h"

#include "platform.h"

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
# define BOOL EXEC_BOOL
# include <proto/dos.h>
# undef BOOL
#endif

#ifdef OF_WII
# define BOOL OGC_BOOL







|







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifdef OF_HAVE_SCHED_YIELD
# include <sched.h>
#endif
#include "unistd_wrapper.h"

#include "platform.h"

#ifdef OF_MORPHOS
# define BOOL EXEC_BOOL
# include <proto/dos.h>
# undef BOOL
#endif

#ifdef OF_WII
# define BOOL OGC_BOOL
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
	rqtp.tv_sec = (time_t)timeInterval;
	rqtp.tv_nsec = lrint((timeInterval - rqtp.tv_sec) * 1000000000);

	if (rqtp.tv_sec != floor(timeInterval))
		@throw [OFOutOfRangeException exception];

	nanosleep(&rqtp, NULL);
#elif defined(OF_MORPHOS) && !defined(OF_IXEMUL)
	if (timeInterval * 50 > ULONG_MAX)
		@throw [OFOutOfRangeException exception];

	Delay(timeInterval * 50);
#elif defined(OF_NINTENDO_DS)
	uint64_t counter;








|







191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
	rqtp.tv_sec = (time_t)timeInterval;
	rqtp.tv_nsec = lrint((timeInterval - rqtp.tv_sec) * 1000000000);

	if (rqtp.tv_sec != floor(timeInterval))
		@throw [OFOutOfRangeException exception];

	nanosleep(&rqtp, NULL);
#elif defined(OF_MORPHOS)
	if (timeInterval * 50 > ULONG_MAX)
		@throw [OFOutOfRangeException exception];

	Delay(timeInterval * 50);
#elif defined(OF_NINTENDO_DS)
	uint64_t counter;

Modified src/platform.h from [24783424a3] to [8c9d997773].

93
94
95
96
97
98
99

100

101
102
103
104
105
106
107
108
109
#elif defined(__DragonFly__)
# define OF_DRAGONFLYBSD
#elif defined(__ANDROID__)
# define OF_ANDROID
#elif defined(__HAIKU__)
# define OF_HAIKU
#elif defined(__MORPHOS__)

# define OF_MORPHOS

# ifdef __ixemul__
#  define OF_IXEMUL
# endif
#elif defined(__sun__)
# define OF_SOLARIS
#elif defined(__QNX__)
# define OF_QNX
#elif defined(__wii__)
# define OF_WII







>
|
>
|
|







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#elif defined(__DragonFly__)
# define OF_DRAGONFLYBSD
#elif defined(__ANDROID__)
# define OF_ANDROID
#elif defined(__HAIKU__)
# define OF_HAIKU
#elif defined(__MORPHOS__)
# ifndef __ixemul__
#  define OF_MORPHOS
#  define OF_AMIGAOS_LIKE
# else
#  define OF_MORPHOS_IXEMUL
# endif
#elif defined(__sun__)
# define OF_SOLARIS
#elif defined(__QNX__)
# define OF_QNX
#elif defined(__wii__)
# define OF_WII

Modified src/socket.h from [a30a66785b] to [1d3c37e76e].

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#endif

#include <stdbool.h>

#import "platform.h"

#ifdef OF_HAVE_SYS_SOCKET_H
# if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
#  define BOOL EXEC_BOOL
# endif
# include <sys/socket.h>
# if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
#  undef BOOL
# endif
#endif
#ifdef OF_HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef OF_HAVE_NETINET_TCP_H







|



|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#endif

#include <stdbool.h>

#import "platform.h"

#ifdef OF_HAVE_SYS_SOCKET_H
# ifdef OF_MORPHOS
#  define BOOL EXEC_BOOL
# endif
# include <sys/socket.h>
# ifdef OF_MORPHOS
#  undef BOOL
# endif
#endif
#ifdef OF_HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef OF_HAVE_NETINET_TCP_H
50
51
52
53
54
55
56
57
58
59
60




61



62
63
64
65
66
67
68
#  endif
# endif
# include <windows.h>
# include <ws2tcpip.h>
#endif

#ifdef OF_MORPHOS
# ifndef OF_IXEMUL
typedef long socklen_t;
# else
typedef int socklen_t;




#endif




struct sockaddr_storage {
	uint8_t ss_len;
	uint8_t ss_family;
	char ss_data[2 + sizeof(struct in_addr) + 8];
};
#endif







<

|
|
>
>
>
>

>
>
>







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
#  endif
# endif
# include <windows.h>
# include <ws2tcpip.h>
#endif

#ifdef OF_MORPHOS

typedef long socklen_t;

struct sockaddr_storage {
	uint8_t ss_len;
	uint8_t ss_family;
	char ss_data[2 + sizeof(struct in_addr) + 8];
};
#endif

#ifdef OF_MORPHOS_IXEMUL
typedef int socklen_t;

struct sockaddr_storage {
	uint8_t ss_len;
	uint8_t ss_family;
	char ss_data[2 + sizeof(struct in_addr) + 8];
};
#endif

Modified src/socket_helpers.h from [f90819336c] to [e85ec3eda4].

57
58
59
60
61
62
63
64
65

66


67
68
69
70
71
72
73
#endif

#if !defined(OF_WINDOWS) && !defined(OF_WII)
# define closesocket(sock) close(sock)
#endif

#ifdef OF_MORPHOS
# ifndef OF_IXEMUL
#  define hstrerror(err) "unknown (no hstrerror)"

# endif


typedef uint32_t in_addr_t;
#endif

#ifdef OF_WII
# define accept(sock, addr, addrlen) net_accept(sock, addr, addrlen)
# define bind(sock, addr, addrlen) net_bind(sock, addr, addrlen)
# define closesocket(sock) net_close(sock)







<
|
>
|
>
>







57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74
75
#endif

#if !defined(OF_WINDOWS) && !defined(OF_WII)
# define closesocket(sock) close(sock)
#endif

#ifdef OF_MORPHOS

# define hstrerror(err) "unknown (no hstrerror)"
typedef uint32_t in_addr_t;
#endif

#ifdef OF_MORPHOS_IXEMUL
typedef uint32_t in_addr_t;
#endif

#ifdef OF_WII
# define accept(sock, addr, addrlen) net_accept(sock, addr, addrlen)
# define bind(sock, addr, addrlen) net_bind(sock, addr, addrlen)
# define closesocket(sock) net_close(sock)

Modified src/unistd_wrapper.h from [33a8d48723] to [1cb41ddd18].

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

#include "config.h"

#include <stdlib.h>	/* Make sure we have any libc include */

#import "platform.h"

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
# define BOOL EXEC_BOOL
# include <exec/types.h>
# undef BOOL
#endif

#if defined(HAVE_UNISTD_H)
# ifdef __GLIBC__







|







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

#include "config.h"

#include <stdlib.h>	/* Make sure we have any libc include */

#import "platform.h"

#ifdef OF_MORPHOS
# define BOOL EXEC_BOOL
# include <exec/types.h>
# undef BOOL
#endif

#if defined(HAVE_UNISTD_H)
# ifdef __GLIBC__

Modified utils/ofhash/OFHash.m from [052fd8a01b] to [7cde93b02a].

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"];
#endif

	if ([arguments count] < 2)
		help();







|







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#ifndef OF_MORPHOS
	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"];
#endif

	if ([arguments count] < 2)
		help();

Modified utils/ofhttp/OFHTTP.m from [144754058e] to [09fa3de57a].

266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhttp/lang"];
#endif

	optionsParser = [OFOptionsParser parserWithOptions: options];
	while ((option = [optionsParser nextOption]) != '\0') {







|







266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#ifndef OF_MORPHOS
	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhttp/lang"];
#endif

	optionsParser = [OFOptionsParser parserWithOptions: options];
	while ((option = [optionsParser nextOption]) != '\0') {

Modified utils/ofzip/OFZIP.m from [3560b83228] to [95a3ff60d9].

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofzip/lang"];
#endif

	optionsParser = [OFOptionsParser parserWithOptions: options];
	while ((option = [optionsParser nextOption]) != '\0') {







|







150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

		[OFApplication activateSandbox: sandbox];
	} @finally {
		[sandbox release];
	}
#endif

#ifndef OF_MORPHOS
	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofzip/lang"];
#endif

	optionsParser = [OFOptionsParser parserWithOptions: options];
	while ((option = [optionsParser nextOption]) != '\0') {