@@ -21,10 +21,11 @@ #import "amiga-library.h" #import "macros.h" #import "private.h" #include +#include struct ObjFWRTBase; #import "inline.h" @@ -74,10 +75,32 @@ static int * get_errno(void) { return &errno; } + +static void +error(const char *string, ULONG arg) +{ + struct Library *IntuitionBase = OpenLibrary("intuition.library", 0); + + if (IntuitionBase != NULL) { + struct EasyStruct easy = { + .es_StructSize = sizeof(easy), + .es_Flags = 0, + .es_Title = (UBYTE *)NULL, + .es_TextFormat = (UBYTE *)string, + (UBYTE *)"OK" + }; + + EasyRequest(NULL, &easy, NULL, arg); + + CloseLibrary(IntuitionBase); + } + + exit(EXIT_FAILURE); +} static void __attribute__((__used__)) ctor(void) { static bool initialized = false; @@ -84,13 +107,10 @@ struct objc_libc libc = { .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free, - .vfprintf = vfprintf, - .fflush = fflush, - .abort = abort, #ifdef HAVE_SJLJ_EXCEPTIONS ._Unwind_SjLj_RaiseException = _Unwind_SjLj_RaiseException, #else ._Unwind_RaiseException = _Unwind_RaiseException, #endif @@ -116,36 +136,27 @@ #ifdef OF_MORPHOS .__register_frame = __register_frame, .__deregister_frame = __deregister_frame, #endif .get_errno = get_errno, +#ifdef OF_AMIGAOS_M68K + .vsnprintf = vsnprintf, +#endif + .atexit = atexit, + .exit = exit, }; if (initialized) return; if ((ObjFWRTBase = OpenLibrary(OBJFWRT_AMIGA_LIB, - OBJFWRT_LIB_MINOR)) == NULL) { - /* - * The linklib is used by objfw(68k).library as well, so we - * can't have the compiler optimize this to another function, - * hence the use of an unnecessary format specifier. - */ - fprintf(stderr, "Failed to open %s!\n", OBJFWRT_AMIGA_LIB); - abort(); - } - - if (!glue_objc_init(1, &libc, __sF)) { - /* - * The linklib is used by objfw(68k).library as well, so we - * can't have the compiler optimize this to another function, - * hence the use of an unnecessary format specifier. - */ - fprintf(stderr, "Failed to initialize %s!\n", - OBJFWRT_AMIGA_LIB); - abort(); - } + OBJFWRT_LIB_MINOR)) == NULL) + error("Failed to open " OBJFWRT_AMIGA_LIB " version %lu!", + OBJFWRT_LIB_MINOR); + + if (!glue_objc_init(1, &libc, __sF)) + error("Failed to initialize " OBJFWRT_AMIGA_LIB "!", 0); initialized = true; } static void __attribute__((__used__))