prevent null pointer access crashes/memory trashing.
[AROS.git] / compiler / stdc / __optionallibs.c
blobfa1b8bb4eeb6a08e4e3768f69e48362d0049722b
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 */
5 #include <proto/exec.h>
6 #include <proto/locale.h>
7 #include <proto/intuition.h>
9 /* Internal function __libfindandopen will only open a library when it is
10 already in the list of open libraries
12 struct LocaleBase *LocaleBase = NULL;
13 struct IntuitionBase *IntuitionBase = NULL;
15 static struct Library *__libfindandopen(const char *libname, int version)
17 struct Node *found;
19 Forbid();
20 found = FindName(&SysBase->LibList, libname);
21 Permit();
23 return (found != NULL) ? OpenLibrary(libname, version) : NULL;
26 int __locale_available(void)
28 if (LocaleBase == NULL)
29 LocaleBase = (struct LocaleBase *)__libfindandopen("locale.library", 0);
31 return LocaleBase != NULL;
34 int __intuition_available(void)
36 if (IntuitionBase == NULL)
37 IntuitionBase = (struct IntuitionBase *)__libfindandopen("intuition.library", 0);
39 return IntuitionBase != NULL;