diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index 9920c67..95fdd9f 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.68k,v 1.46 2005-03-20 17:14:58 obarthel Exp $ +# $Id: GNUmakefile.68k,v 1.47 2005-03-30 19:37:13 obarthel Exp $ # # :ts=8 # @@ -346,6 +346,7 @@ C_LIB = \ stdlib_system.o \ stdlib_termination_message.o \ stdlib_threshold.o \ + stdlib_utilitybase.o \ stdlib_udivsi3.o \ stdlib_udivsi4.o \ stdlib_umodsi3.o \ diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index 97132a3..9122c59 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.os4,v 1.48 2005-03-26 10:53:35 obarthel Exp $ +# $Id: GNUmakefile.os4,v 1.49 2005-03-30 19:37:24 obarthel Exp $ # # :ts=8 # @@ -345,6 +345,7 @@ C_LIB = \ stdlib_system.o \ stdlib_termination_message.o \ stdlib_threshold.o \ + stdlib_utilitybase.o \ stdlib_udivsi3.o \ stdlib_udivsi4.o \ stdlib_umodsi3.o \ diff --git a/library/changes b/library/changes index 850fb6d..b2f3c4b 100644 --- a/library/changes +++ b/library/changes @@ -15,6 +15,11 @@ effect of printing a different termination message but otherwise program flow takes the same path as abort(). +- Moved the __UtilityBase/__IUtility variable declarations into + a separate file. + +- Simplified the library/open close code in "stdlib_main.c". + c.lib 1.190 (25.3.2005) diff --git a/library/ctype_headers.h b/library/ctype_headers.h index cb1bf35..69cbb11 100644 --- a/library/ctype_headers.h +++ b/library/ctype_headers.h @@ -1,5 +1,5 @@ /* - * $Id: ctype_headers.h,v 1.3 2005-03-18 12:38:22 obarthel Exp $ + * $Id: ctype_headers.h,v 1.4 2005-03-30 19:37:26 obarthel Exp $ * * :ts=4 * @@ -42,9 +42,13 @@ /****************************************************************************/ -#ifndef _STDLIB_LOCALE_UTILITY_H -#include "stdlib_locale_utility.h" -#endif /* _STDLIB_LOCALE_UTILITY_H */ +#ifndef _STDLIB_LOCALEBASE_H +#include "stdlib_localebase.h" +#endif /* _STDLIB_LOCALEBASE_H */ + +#ifndef _STDLIB_UTILITYBASE_H +#include "stdlib_utilitybase.h" +#endif /* _STDLIB_UTILITYBASE_H */ /****************************************************************************/ diff --git a/library/smakefile b/library/smakefile index 99284aa..dcd000c 100644 --- a/library/smakefile +++ b/library/smakefile @@ -1,5 +1,5 @@ # -# $Id: smakefile,v 1.35 2005-03-19 11:06:57 obarthel Exp $ +# $Id: smakefile,v 1.36 2005-03-30 19:37:26 obarthel Exp $ # # :ts=8 # @@ -439,6 +439,7 @@ STDLIB_OBJ = \ stdlib_swapstack.o \ stdlib_system.o \ stdlib_unsetenv.o \ + stdlib_utilitybase.o \ stdlib_wildcard_expand.o \ stdlib_stdio_window_spec.o diff --git a/library/stdlib_headers.h b/library/stdlib_headers.h index 655c089..8897974 100644 --- a/library/stdlib_headers.h +++ b/library/stdlib_headers.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib_headers.h,v 1.16 2005-03-18 12:38:24 obarthel Exp $ + * $Id: stdlib_headers.h,v 1.17 2005-03-30 19:37:27 obarthel Exp $ * * :ts=4 * @@ -106,9 +106,13 @@ /****************************************************************************/ -#ifndef _STDLIB_LOCALE_UTILITY_H -#include "stdlib_locale_utility.h" -#endif /* _STDLIB_LOCALE_UTILITY_H */ +#ifndef _STDLIB_LOCALEBASE_H +#include "stdlib_localebase.h" +#endif /* _STDLIB_LOCALEBASE_H */ + +#ifndef _STDLIB_UTILITYBASE_H +#include "stdlib_utilitybase.h" +#endif /* _STDLIB_UTILITYBASE_H */ /****************************************************************************/ diff --git a/library/stdlib_localebase.h b/library/stdlib_localebase.h new file mode 100644 index 0000000..864c55b --- /dev/null +++ b/library/stdlib_localebase.h @@ -0,0 +1,88 @@ +/* + * $Id: stdlib_localebase.h,v 1.1 2005-03-30 19:37:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_LOCALEBASE_H +#define _STDLIB_LOCALEBASE_H + +/****************************************************************************/ + +#ifndef __NOLIBBASE__ +#define __NOLIBBASE__ +#endif /* __NOLIBBASE__ */ + +#ifndef __NOGLOBALIFACE__ +#define __NOGLOBALIFACE__ +#endif /* __NOGLOBALIFACE__ */ + +#include + +/****************************************************************************/ + +#ifndef _MACROS_H +#include "macros.h" +#endif /* _MACROS_H */ + +/****************************************************************************/ + +extern struct Library * NOCOMMON __LocaleBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) + +/****************************************************************************/ + +extern struct LocaleIFace NOCOMMON * __ILocale; + +/****************************************************************************/ + +#define DECLARE_LOCALEBASE() \ + struct Library * UNUSED LocaleBase = __LocaleBase; \ + struct LocaleIFace * ILocale = __ILocale + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +#define DECLARE_LOCALEBASE() \ + struct Library * LocaleBase = __LocaleBase + +/****************************************************************************/ + +#endif /* __amigaos4__ */ + +/****************************************************************************/ + +#endif /* _STDLIB_LOCALEBASE_H */ diff --git a/library/stdlib_main.c b/library/stdlib_main.c index e88c7a4..1d9e3af 100644 --- a/library/stdlib_main.c +++ b/library/stdlib_main.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_main.c,v 1.20 2005-03-20 11:18:06 obarthel Exp $ + * $Id: stdlib_main.c,v 1.21 2005-03-30 19:37:43 obarthel Exp $ * * :ts=4 * @@ -147,18 +147,86 @@ call_main(void) /****************************************************************************/ -STATIC VOID ASM -detach_cleanup(REG(d0, LONG UNUSED unused_return_code),REG(d1, BPTR segment_list)) +STATIC BOOL +open_libraries(VOID) +{ + BOOL success = FALSE; + int os_version; + + /* Check which minimum operating system version we actually require. */ + os_version = 37; + if(__minimum_os_lib_version > 37) + os_version = __minimum_os_lib_version; + + /* Open the minimum required libraries. */ + DOSBase = (struct Library *)OpenLibrary("dos.library",os_version); + if(DOSBase == NULL) + goto out; + + __UtilityBase = OpenLibrary("utility.library",os_version); + if(__UtilityBase == NULL) + goto out; + + #if defined(__amigaos4__) + { + /* Obtain the interfaces for these libraries. */ + IDOS = (struct DOSIFace *)GetInterface(DOSBase, "main", 1, 0); + if(IDOS == NULL) + goto out; + + __IUtility = (struct UtilityIFace *)GetInterface(__UtilityBase, "main", 1, 0); + if(__IUtility == NULL) + goto out; + } + #endif /* __amigaos4__ */ + + success = TRUE; + + out: + + return(success); +} + +/****************************************************************************/ + +STATIC VOID +close_libraries(VOID) { #if defined(__amigaos4__) { if(__IUtility != NULL) + { DropInterface((struct Interface *)__IUtility); + __IUtility = NULL; + } if(IDOS != NULL) + { DropInterface((struct Interface *)IDOS); + IDOS = NULL; + } } - #else + #endif /* __amigaos4__ */ + + if(__UtilityBase != NULL) + { + CloseLibrary(__UtilityBase); + __UtilityBase = NULL; + } + + if(DOSBase != NULL) + { + CloseLibrary(DOSBase); + DOSBase = NULL; + } +} + +/****************************************************************************/ + +STATIC VOID ASM +detach_cleanup(REG(d0, LONG UNUSED unused_return_code),REG(d1, BPTR segment_list)) +{ + #if NOT defined(__amigaos4__) { /* The following trick is necessary only under dos.library V40 and below. */ if(((struct Library *)DOSBase)->lib_Version < 50) @@ -177,11 +245,7 @@ detach_cleanup(REG(d0, LONG UNUSED unused_return_code),REG(d1, BPTR segment_list } #endif /* __amigaos4__ */ - if(__UtilityBase != NULL) - CloseLibrary(__UtilityBase); - - if(DOSBase != NULL) - CloseLibrary(DOSBase); + close_libraries(); } /****************************************************************************/ @@ -204,17 +268,6 @@ get_stack_size(void) /****************************************************************************/ -/* The global utility.library base, as required by clib2. */ -struct Library * __UtilityBase; - -/****************************************************************************/ - -#if defined(__amigaos4__) -struct UtilityIFace * __IUtility; -#endif /* __amigaos4__ */ - -/****************************************************************************/ - int _main(void) { @@ -225,7 +278,6 @@ _main(void) struct Process * this_process; int return_code = RETURN_FAIL; ULONG current_stack_size; - int os_version; SysBase = *(struct Library **)4; @@ -254,43 +306,30 @@ _main(void) __WBenchMsg = (struct WBStartup *)startup_message; - /* Check which minimum operating system version we actually require. */ - os_version = 37; - if(__minimum_os_lib_version > 37) - os_version = __minimum_os_lib_version; - - /* We will need dos.library V37 and utility.library V37. */ - DOSBase = (struct Library *)OpenLibrary("dos.library",os_version); - __UtilityBase = OpenLibrary("utility.library",os_version); - - if(DOSBase == NULL || __UtilityBase == NULL) + /* Try to open the libraries we need to proceed. */ + if(CANNOT open_libraries()) { char * error_message; /* If available, use the error message provided by the client. */ - if(__minimum_os_lib_error != NULL) - error_message = __minimum_os_lib_error; - else - error_message = "This program requires AmigaOS 2.04 or higher."; + error_message = __minimum_os_lib_error; + + #if defined(__amigaos4__) + { + if(error_message == NULL) + error_message = "This program requires AmigaOS 4.0 or higher."; + } + #else + { + if(error_message == NULL) + error_message = "This program requires AmigaOS 2.04 or higher."; + } + #endif /* __amigaos4__ */ __show_error(error_message); goto out; } - #if defined(__amigaos4__) - { - /* Get interfaces for DOS and Utility */ - IDOS = (struct DOSIFace *)GetInterface(DOSBase, "main", 1, 0); - __IUtility = (struct UtilityIFace *)GetInterface(__UtilityBase, "main", 1, 0); - - if (IDOS == NULL || __IUtility == NULL) - { - __show_error("This program requires AmigaOS 4.0 or higher."); - goto out; - } - } - #endif /* __amigaos4__ */ - if(__disable_dos_requesters) { /* Don't display any requesters. */ @@ -483,39 +522,7 @@ _main(void) __set_process_window(old_window_pointer); if(child_process == NULL) - { - #if defined(__amigaos4__) - { - if(__IUtility != NULL) - { - DropInterface((struct Interface *)__IUtility); - __IUtility = NULL; - } - } - #endif /* __amigaos4__ */ - - if(__UtilityBase != NULL) - { - CloseLibrary(__UtilityBase); - __UtilityBase = NULL; - } - - #if defined(__amigaos4__) - { - if(IDOS != NULL) - { - DropInterface((struct Interface *)IDOS); - IDOS = NULL; - } - } - #endif /* __amigaos4__ */ - - if(DOSBase != NULL) - { - CloseLibrary(DOSBase); - DOSBase = NULL; - } - } + close_libraries(); if(startup_message != NULL) { diff --git a/library/stdlib_utilitybase.c b/library/stdlib_utilitybase.c new file mode 100644 index 0000000..3dcd3fa --- /dev/null +++ b/library/stdlib_utilitybase.c @@ -0,0 +1,50 @@ +/* + * $Id: stdlib_utilitybase.c,v 1.1 2005-03-30 19:37:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#define __NOLIBBASE__ + +#ifndef PROTO_UTILITY_H +#include +#endif /* PROTO_UTILITY_H */ + +/****************************************************************************/ + +struct Library * __UtilityBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) + +struct UtilityIFace * __IUtility; + +#endif /* __amigaos4__ */ diff --git a/library/stdlib_locale_utility.h b/library/stdlib_utilitybase.h similarity index 83% rename from library/stdlib_locale_utility.h rename to library/stdlib_utilitybase.h index 0ef5a64..d455bf4 100644 --- a/library/stdlib_locale_utility.h +++ b/library/stdlib_utilitybase.h @@ -1,5 +1,5 @@ /* - * $Id: stdlib_locale_utility.h,v 1.3 2005-01-02 09:07:18 obarthel Exp $ + * $Id: stdlib_utilitybase.h,v 1.1 2005-03-30 19:37:47 obarthel Exp $ * * :ts=4 * @@ -31,8 +31,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _STDLIB_LOCALE_UTILITY_H -#define _STDLIB_LOCALE_UTILITY_H +#ifndef _STDLIB_UTILITYBASE_H +#define _STDLIB_UTILITYBASE_H /****************************************************************************/ @@ -45,7 +45,6 @@ #endif /* __NOGLOBALIFACE__ */ #include -#include /****************************************************************************/ @@ -56,7 +55,6 @@ /****************************************************************************/ extern struct Library * NOCOMMON __UtilityBase; -extern struct Library * NOCOMMON __LocaleBase; /****************************************************************************/ @@ -64,8 +62,7 @@ extern struct Library * NOCOMMON __LocaleBase; /****************************************************************************/ -extern struct UtilityIFace NOCOMMON * __IUtility; -extern struct LocaleIFace NOCOMMON * __ILocale; +extern struct UtilityIFace NOCOMMON * __IUtility; /****************************************************************************/ @@ -73,10 +70,6 @@ extern struct LocaleIFace NOCOMMON * __ILocale; struct Library * UNUSED UtilityBase = __UtilityBase; \ struct UtilityIFace * IUtility = __IUtility -#define DECLARE_LOCALEBASE() \ - struct Library * UNUSED LocaleBase = __LocaleBase; \ - struct LocaleIFace * ILocale = __ILocale - /****************************************************************************/ #else @@ -86,13 +79,10 @@ extern struct LocaleIFace NOCOMMON * __ILocale; #define DECLARE_UTILITYBASE() \ struct Library * UtilityBase = __UtilityBase -#define DECLARE_LOCALEBASE() \ - struct Library * LocaleBase = __LocaleBase - /****************************************************************************/ #endif /* __amigaos4__ */ /****************************************************************************/ -#endif /* _STDLIB_LOCALE_UTILITY_H */ +#endif /* _STDLIB_UTILITYBASE_H */ diff --git a/library/string_headers.h b/library/string_headers.h index 4477dfd..30858f5 100644 --- a/library/string_headers.h +++ b/library/string_headers.h @@ -1,5 +1,5 @@ /* - * $Id: string_headers.h,v 1.5 2005-03-18 12:38:25 obarthel Exp $ + * $Id: string_headers.h,v 1.6 2005-03-30 19:37:47 obarthel Exp $ * * :ts=4 * @@ -46,9 +46,13 @@ /****************************************************************************/ -#ifndef _STDLIB_LOCALE_UTILITY_H -#include "stdlib_locale_utility.h" -#endif /* _STDLIB_LOCALE_UTILITY_H */ +#ifndef _STDLIB_LOCALEBASE_H +#include "stdlib_localebase.h" +#endif /* _STDLIB_LOCALEBASE_H */ + +#ifndef _STDLIB_UTILITYBASE_H +#include "stdlib_utilitybase.h" +#endif /* _STDLIB_UTILITYBASE_H */ /****************************************************************************/ diff --git a/library/time_headers.h b/library/time_headers.h index 4410be5..0761156 100644 --- a/library/time_headers.h +++ b/library/time_headers.h @@ -1,5 +1,5 @@ /* - * $Id: time_headers.h,v 1.10 2005-03-18 12:38:25 obarthel Exp $ + * $Id: time_headers.h,v 1.11 2005-03-30 19:37:47 obarthel Exp $ * * :ts=4 * @@ -90,9 +90,13 @@ /****************************************************************************/ -#ifndef _STDLIB_LOCALE_UTILITY_H -#include "stdlib_locale_utility.h" -#endif /* _STDLIB_LOCALE_UTILITY_H */ +#ifndef _STDLIB_LOCALEBASE_H +#include "stdlib_localebase.h" +#endif /* _STDLIB_LOCALEBASE_H */ + +#ifndef _STDLIB_UTILITYBASE_H +#include "stdlib_utilitybase.h" +#endif /* _STDLIB_UTILITYBASE_H */ /****************************************************************************/