Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -16,16 +16,15 @@ */ #import "OFSeekableStream.h" #import "OFKernelEventObserver.h" -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS # define OF_FILE_HANDLE_IS_FD # define OF_INVALID_FILE_HANDLE (-1) typedef int of_file_handle_t; #else -# include # define OF_INVALID_FILE_HANDLE NULL typedef struct of_file_handle *of_file_handle_t; #endif OF_ASSUME_NONNULL_BEGIN Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -54,10 +54,17 @@ #ifdef OF_NINTENDO_DS # include # include #endif + +#ifdef OF_AMIGAOS +# ifdef OF_AMIGAOS3 +# define INTUITION_CLASSES_H +# endif +# include +#endif #ifndef O_BINARY # define O_BINARY 0 #endif #ifndef O_CLOEXEC @@ -68,11 +75,11 @@ #endif #ifndef O_EXLOCK # define O_EXLOCK 0 #endif -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS # define closeHandle(h) close(h) #else struct of_file_handle { of_file_handle_t previous, next; BPTR handle; @@ -101,11 +108,11 @@ iter = iter->next) Close(iter->handle); } #endif -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS static int parseMode(const char *mode) { if (strcmp(mode, "r") == 0) return O_RDONLY; @@ -207,11 +214,11 @@ @try { void *pool = objc_autoreleasePoolPush(); int flags; -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS if ((flags = parseMode([mode UTF8String])) == -1) @throw [OFInvalidArgumentException exception]; flags |= O_BINARY | O_CLOEXEC; @@ -268,12 +275,16 @@ mode: mode errNo: errNo]; } if (handle->append) { +# ifdef OF_MORPHOS if (Seek64(handle->handle, 0, OFFSET_END) == -1) { +# else + if (Seek(handle->handle, 0, OFFSET_END) == -1) { +# endif Close(handle->handle); @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: EIO]; @@ -361,11 +372,11 @@ if ((ret = read(_handle, buffer, (unsigned int)length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: errno]; -#elif defined(OF_MORPHOS) +#elif defined(OF_AMIGAOS) if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if ((ret = Read(_handle->handle, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self @@ -399,18 +410,22 @@ if ((bytesWritten = write(_handle, buffer, (int)length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; -#elif defined(OF_MORPHOS) +#elif defined(OF_AMIGAOS) LONG bytesWritten; if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if (_handle->append) { +# ifdef OF_MORPHOS if (Seek64(_handle->handle, 0, OFFSET_END) == -1) +# else + if (Seek(_handle->handle, 0, OFFSET_END) == -1) +# endif @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: EIO]; @@ -443,11 +458,11 @@ of_offset_t ret; if (_handle == OF_INVALID_FILE_HANDLE) @throw [OFNotOpenException exceptionWithObject: self]; -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS # if defined(OF_WINDOWS) ret = _lseeki64(_handle, offset, whence); # elif defined(OF_HAVE_OFF64_T) ret = lseek64(_handle, offset, whence); # else @@ -458,26 +473,34 @@ @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: errno]; #else + LONG translatedWhence; + switch (whence) { case SEEK_SET: - ret = Seek64(_handle->handle, offset, OFFSET_BEGINNING); + translatedWhence = OFFSET_BEGINNING; break; case SEEK_CUR: - ret = Seek64(_handle->handle, offset, OFFSET_CURRENT); + translatedWhence = OFFSET_CURRENT; break; case SEEK_END: - ret = Seek64(_handle->handle, offset, OFFSET_END); + translatedWhence = OFFSET_END; break; default: - ret = -1; - break; + @throw [OFSeekFailedException exceptionWithStream: self + offset: offset + whence: whence + errNo: EINVAL]; } - if (ret == -1) +# ifdef OF_MORPHOS + if ((ret = Seek64(_handle->handle, offset, translatedWhence)) == 1) +# else + if ((ret = Seek(_handle->handle, offset, translatedWhence)) == 1) +# endif @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: EINVAL]; #endif Index: src/OFFileManager.h ================================================================== --- src/OFFileManager.h +++ src/OFFileManager.h @@ -21,20 +21,20 @@ OF_ASSUME_NONNULL_BEGIN /*! @file */ -#if defined(OF_HAVE_CHMOD) && !defined(OF_MORPHOS) +#if defined(OF_HAVE_CHMOD) && !defined(OF_AMIGAOS) # define OF_FILE_MANAGER_SUPPORTS_PERMISSIONS #endif -#if defined(OF_HAVE_CHOWN) && !defined(OF_MORPHOS) +#if defined(OF_HAVE_CHOWN) && !defined(OF_AMIGAOS) # define OF_FILE_MANAGER_SUPPORTS_OWNER #endif -#if (defined(OF_HAVE_LINK) && !defined(OF_MORPHOS)) || defined(OF_WINDOWS) +#if (defined(OF_HAVE_LINK) && !defined(OF_AMIGAOS)) || defined(OF_WINDOWS) # define OF_FILE_MANAGER_SUPPORTS_LINKS #endif -#if (defined(OF_HAVE_SYMLINK) && !defined(OF_MORPHOS)) || defined(OF_WINDOWS) +#if (defined(OF_HAVE_SYMLINK) && !defined(OF_AMIGAOS)) || defined(OF_WINDOWS) # define OF_FILE_MANAGER_SUPPORTS_SYMLINKS #endif @class OFArray OF_GENERIC(ObjectType); @class OFDate; Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -54,11 +54,15 @@ # include # include # include #endif -#ifdef OF_MORPHOS +#ifdef OF_AMIGAOS +# ifdef OF_AMIGAOS3 +# define INTUITION_CLASSES_H +# endif +# include # include # include #endif @interface OFFileManager_default: OFFileManager @@ -96,11 +100,11 @@ const of_file_type_t of_file_type_character_special = @"of_file_type_character_special"; const of_file_type_t of_file_type_block_special = @"of_file_type_block_special"; const of_file_type_t of_file_type_socket = @"of_file_type_socket"; -#ifdef OF_MORPHOS +#ifdef OF_AMIGAOS static bool dirChanged = false; static BPTR originalDirLock = 0; OF_DESTRUCTOR() { @@ -147,11 +151,11 @@ } @finally { free(buffer); } return ret; -#elif defined(OF_MORPHOS) +#elif defined(OF_AMIGAOS) char buffer[512]; if (!NameFromLock(((struct Process *)FindTask(NULL))->pr_CurrentDir, buffer, 512)) { if (IoErr() == ERROR_LINE_TOO_LONG) @@ -402,11 +406,11 @@ #if defined(OF_WINDOWS) if (_wchdir([path UTF16String]) != 0) @throw [OFChangeCurrentDirectoryPathFailedException exceptionWithPath: path errNo: errno]; -#elif defined(OF_MORPHOS) +#elif defined(OF_AMIGAOS) BPTR lock, oldLock; if ((lock = Lock([path cStringWithEncoding: [OFLocalization encoding]], SHARED_LOCK)) == 0) { int errNo; Index: src/OFLocalization.m ================================================================== --- src/OFLocalization.m +++ src/OFLocalization.m @@ -224,14 +224,16 @@ * Returns an empty string on MorphOS + libnix, but still * applies it so that printf etc. work as expected. */ setlocale(LC_ALL, ""); -# ifdef OF_MORPHOS +# if defined(OF_MORPHOS) if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) { -# else +# elif defined(OF_AMIGAOS4) if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) { +# else + if (0) { # endif of_string_encoding_t ASCII = OF_STRING_ENCODING_ASCII; @try { _encoding = of_string_parse_encoding( Index: src/OFStdIOStream+Private.h ================================================================== --- src/OFStdIOStream+Private.h +++ src/OFStdIOStream+Private.h @@ -18,14 +18,14 @@ #import "OFStdIOStream.h" OF_ASSUME_NONNULL_BEGIN @interface OFStdIOStream () -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS - (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 Index: src/OFStdIOStream.h ================================================================== --- src/OFStdIOStream.h +++ src/OFStdIOStream.h @@ -16,12 +16,18 @@ */ #import "OFStream.h" #import "OFKernelEventObserver.h" -#ifdef OF_MORPHOS +#ifdef OF_AMIGAOS +# ifdef OF_AMIGAOS3 +# define INTUITION_CLASSES_H +# endif # include +# ifdef OF_AMIGAOS3 +# undef INTUITION_CLASSES_H +# endif #endif OF_ASSUME_NONNULL_BEGIN /*! @@ -34,15 +40,15 @@ */ #ifdef OF_STDIO_STREAM_WIN32_CONSOLE_H OF_SUBCLASSING_RESTRICTED #endif @interface OFStdIOStream: OFStream -#if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) +#if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) #endif { -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS int _fd; #else BPTR _handle; bool _closable; #endif Index: src/OFStdIOStream.m ================================================================== --- src/OFStdIOStream.m +++ src/OFStdIOStream.m @@ -39,11 +39,14 @@ #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" -#ifdef OF_MORPHOS +#ifdef OF_AMIGAOS +# ifdef OF_AMIGAOS3 +# define INTUITION_CLASSES_H +# endif # include #endif /* References for static linking */ #ifdef OF_WINDOWS @@ -56,11 +59,11 @@ OFStdIOStream *of_stdin = nil; OFStdIOStream *of_stdout = nil; OFStdIOStream *of_stderr = nil; -#ifdef OF_MORPHOS +#ifdef OF_AMIGAOS OF_DESTRUCTOR() { [of_stdin dealloc]; [of_stdout dealloc]; [of_stderr dealloc]; @@ -96,11 +99,11 @@ @implementation OFStdIOStream #ifndef OF_WINDOWS + (void)load { -# ifndef OF_MORPHOS +# ifndef OF_AMIGAOS 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(); @@ -136,11 +139,11 @@ - (instancetype)init { OF_INVALID_INIT_METHOD } -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS - (instancetype)of_initWithFileDescriptor: (int)fd { self = [super init]; _fd = fd; @@ -167,11 +170,11 @@ [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS if (_fd == -1) #else if (_handle == 0) #endif @throw [OFNotOpenException exceptionWithObject: self]; @@ -182,11 +185,11 @@ - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; # ifndef OF_WINDOWS if ((ret = read(_fd, buffer, length)) < 0) @@ -222,11 +225,11 @@ } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; # ifndef OF_WINDOWS ssize_t bytesWritten; @@ -268,11 +271,11 @@ #endif return (size_t)bytesWritten; } -#if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) +#if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) - (int)fileDescriptorForReading { return _fd; } @@ -282,11 +285,11 @@ } #endif - (void)close { -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS if (_fd != -1) close(_fd); _fd = -1; #else @@ -318,11 +321,11 @@ return OF_RETAIN_COUNT_MAX; } - (int)columns { -#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_MORPHOS) +#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_AMIGAOS) struct winsize ws; if (ioctl(_fd, TIOCGWINSZ, &ws) != 0) return -1; @@ -332,11 +335,11 @@ #endif } - (int)rows { -#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_MORPHOS) +#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_AMIGAOS) struct winsize ws; if (ioctl(_fd, TIOCGWINSZ, &ws) != 0) return -1; Index: src/OFSystemInfo.m ================================================================== --- src/OFSystemInfo.m +++ src/OFSystemInfo.m @@ -214,10 +214,12 @@ #elif defined(OF_ANDROID) /* TODO */ #elif defined(OF_MORPHOS) /* TODO */ #elif defined(OF_AMIGAOS4) + /* TODO */ +#elif defined(OF_AMIGAOS3) /* TODO */ #elif defined(OF_WII) || defined(NINTENDO_3DS) || defined(OF_NINTENDO_DS) || \ defined(OF_PSP) || defined(OF_MSDOS) /* Intentionally nothing */ #elif defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME) Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -30,11 +30,14 @@ #endif #include "unistd_wrapper.h" #include "platform.h" -#ifdef OF_MORPHOS +#ifdef OF_AMIGAOS +# ifdef OF_AMIGAOS3 +# define INTUITION_CLASSES_H +# endif # include #endif #ifdef OF_WII # define nanosleep ogc_nanosleep @@ -82,13 +85,10 @@ #endif #ifdef OF_DJGPP # define lrint(x) rint(x) #endif -#ifdef OF_AMIGAOS3 -# define lrint(x) ((long)x) -#endif #ifdef OF_HAVE_THREADS # import "threading.h" static of_tlskey_t threadSelfKey; @@ -206,11 +206,11 @@ if (rqtp.tv_sec != floor(timeInterval)) @throw [OFOutOfRangeException exception]; nanosleep(&rqtp, NULL); -#elif defined(OF_MORPHOS) +#elif defined(OF_AMIGAOS) if (timeInterval * 50 > ULONG_MAX) @throw [OFOutOfRangeException exception]; Delay(timeInterval * 50); #elif defined(OF_NINTENDO_DS) Index: src/OFURLHandler_file.m ================================================================== --- src/OFURLHandler_file.m +++ src/OFURLHandler_file.m @@ -64,18 +64,21 @@ # include # include # include #endif -#ifdef OF_MORPHOS +#ifdef OF_AMIGAOS +# ifdef OF_AMIGAOS3 +# define INTUITION_CLASSES_H +# endif # include # include #endif #if defined(OF_WINDOWS) typedef struct __stat64 of_stat_t; -#elif defined(OF_MORPHOS) +#elif defined(OF_AMIGAOS) typedef struct { of_offset_t st_size; mode_t st_mode; of_time_interval_t st_atime, st_mtime, st_ctime; } of_stat_t; @@ -87,11 +90,11 @@ #ifndef S_ISLNK # define S_ISLNK(s) 0 #endif -#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS) && !defined(OF_MORPHOS) +#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS) && !defined(OF_AMIGAOS) static OFMutex *passwdMutex; #endif #if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) && !defined(OF_WINDOWS) static OFMutex *readdirMutex; #endif @@ -103,11 +106,11 @@ static int of_stat(OFString *path, of_stat_t *buffer) { #if defined(OF_WINDOWS) return _wstat64([path UTF16String], buffer); -#elif defined(OF_MORPHOS) +#elif defined(OF_AMIGAOS) BPTR lock; struct FileInfoBlock fib; of_time_interval_t timeInterval; struct Locale *locale; @@ -127,20 +130,28 @@ } return -1; } +# ifdef OF_MORPHOS if (!Examine64(lock, &fib, TAG_DONE)) { +# else + if (!Examine(lock, &fib)) { +# endif UnLock(lock); errno = 0; return -1; } UnLock(lock); +# ifdef OF_MORPHOS buffer->st_size = fib.fib_Size64; +# else + buffer->st_size = fib.fib_Size; +# endif buffer->st_mode = (fib.fib_DirEntryType > 0 ? S_IFDIR : S_IFREG); timeInterval = 252460800; /* 1978-01-01 */ locale = OpenLocale(NULL); @@ -170,11 +181,11 @@ } static int of_lstat(OFString *path, of_stat_t *buffer) { -#if defined(HAVE_LSTAT) && !defined(OF_WINDOWS) && !defined(OF_MORPHOS) +#if defined(HAVE_LSTAT) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) # ifdef OF_HAVE_OFF64_T return lstat64([path cStringWithEncoding: [OFLocalization encoding]], buffer); # else return lstat([path cStringWithEncoding: [OFLocalization encoding]], @@ -658,11 +669,11 @@ #if defined(OF_WINDOWS) if (_wmkdir([path UTF16String]) != 0) @throw [OFCreateDirectoryFailedException exceptionWithURL: URL errNo: errno]; -#elif defined(OF_MORPHOS) +#elif defined(OF_AMIGAOS) BPTR lock; if ((lock = CreateDir( [path cStringWithEncoding: [OFLocalization encoding]])) == 0) { int errNo; @@ -760,11 +771,11 @@ requestedLength: 0 errNo: EIO]; } @finally { FindClose(handle); } -#elif defined(OF_MORPHOS) +#elif defined(OF_AMIGAOS) of_string_encoding_t encoding = [OFLocalization encoding]; BPTR lock; struct FileInfoBlock fib; if ((lock = Lock([path cStringWithEncoding: encoding], @@ -938,11 +949,11 @@ [path stringByAppendingPathComponent: item]]]; objc_autoreleasePoolPop(pool2); } -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS # ifndef OF_WINDOWS if (rmdir([path cStringWithEncoding: [OFLocalization encoding]]) != 0) # else if (_wrmdir([path UTF16String]) != 0) @@ -961,11 +972,11 @@ exceptionWithURL: URL errNo: errno]; #endif } -#ifdef OF_MORPHOS +#ifdef OF_AMIGAOS if (!DeleteFile( [path cStringWithEncoding: [OFLocalization encoding]])) { int errNo; switch (IoErr()) { @@ -1097,11 +1108,11 @@ [[destination fileSystemRepresentation] UTF16String]) != 0) @throw [OFMoveItemFailedException exceptionWithSourceURL: source destinationURL: destination errNo: errno]; -#elif defined(OF_MORPHOS) +#elif defined(OF_AMIGAOS) of_string_encoding_t encoding = [OFLocalization encoding]; if (!Rename([[source fileSystemRepresentation] cStringWithEncoding: encoding], [[destination fileSystemRepresentation] Index: utils/ofhash/OFHash.m ================================================================== --- utils/ofhash/OFHash.m +++ utils/ofhash/OFHash.m @@ -90,11 +90,11 @@ } @finally { [sandbox release]; } #endif -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS [OFLocalization addLanguageDirectory: @LANGUAGE_DIR]; #else [OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"]; #endif Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -394,11 +394,11 @@ } @finally { [sandbox release]; } #endif -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS [OFLocalization addLanguageDirectory: @LANGUAGE_DIR]; #else [OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofhttp/lang"]; #endif Index: utils/ofzip/OFZIP.m ================================================================== --- utils/ofzip/OFZIP.m +++ utils/ofzip/OFZIP.m @@ -181,11 +181,11 @@ } @finally { [sandbox release]; } #endif -#ifndef OF_MORPHOS +#ifndef OF_AMIGAOS [OFLocalization addLanguageDirectory: @LANGUAGE_DIR]; #else [OFLocalization addLanguageDirectory: @"PROGDIR:/share/ofzip/lang"]; #endif