@@ -56,11 +56,16 @@ # include # include #endif #ifdef OF_AMIGAOS -# define __USE_INLINE__ +# ifdef OF_AMIGAOS4 +# define __USE_INLINE__ +# define __NOLIBBASE__ +# define __NOGLOBALIFACE__ +# endif +# include # include #endif #ifndef O_BINARY # define O_BINARY 0 @@ -76,10 +81,16 @@ #endif #ifndef OF_AMIGAOS # define closeHandle(h) close(h) #else +# ifdef OF_AMIGAOS4 +extern struct ExecIFace *IExec; +static struct Library *DOSBase = NULL; +static struct DOSIFace *IDOS = NULL; +# endif + struct of_file_handle { of_file_handle_t previous, next; BPTR handle; bool append; } *firstHandle = NULL; @@ -103,10 +114,18 @@ OF_DESTRUCTOR() { for (of_file_handle_t iter = firstHandle; iter != NULL; iter = iter->next) Close(iter->handle); + +# ifdef OF_AMIGAOS4 + if (IDOS != NULL) + DropInterface(IDOS); + + if (DOSBase != NULL) + CloseLibrary(DOSBase); +# endif } #endif #ifndef OF_AMIGAOS static int @@ -177,10 +196,21 @@ #ifdef OF_NINTENDO_DS if (!nitroFSInit(NULL)) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif + +#ifdef OF_AMIGAOS4 + if ((DOSBase = OpenLibrary("dos.library", 36)) == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: self]; + + if ((IDOS = (struct DOSIFace *) + GetInterface(DOSBase, "main", 1, NULL)) == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: self]; +#endif } + (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode {