| 1 | /* OS/2 compatibility functions.
|
|---|
| 2 | Copyright (C) 2001-2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This program is free software; you can redistribute it and/or modify it
|
|---|
| 5 | under the terms of the GNU Library General Public License as published
|
|---|
| 6 | by the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 7 | any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 12 | Library General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU Library General Public
|
|---|
| 15 | License along with this program; if not, write to the Free Software
|
|---|
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|---|
| 17 | USA. */
|
|---|
| 18 |
|
|---|
| 19 | #define OS2_AWARE
|
|---|
| 20 | #ifdef HAVE_CONFIG_H
|
|---|
| 21 | #include <config.h>
|
|---|
| 22 | #endif
|
|---|
| 23 |
|
|---|
| 24 | #include <stdlib.h>
|
|---|
| 25 | #include <string.h>
|
|---|
| 26 |
|
|---|
| 27 | /* A version of getenv() that works from DLLs */
|
|---|
| 28 | extern unsigned long DosScanEnv (const unsigned char *pszName, unsigned char **ppszValue);
|
|---|
| 29 |
|
|---|
| 30 | char *
|
|---|
| 31 | _nl_getenv (const char *name)
|
|---|
| 32 | {
|
|---|
| 33 | unsigned char *value;
|
|---|
| 34 | if (DosScanEnv (name, &value))
|
|---|
| 35 | return NULL;
|
|---|
| 36 | else
|
|---|
| 37 | return value;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | char _nl_default_dirname[] = /* a 260+1 bytes large buffer */
|
|---|
| 41 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
|---|
| 42 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
|---|
| 43 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
|---|
| 44 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
|---|
| 45 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
|---|
| 46 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
|---|
| 47 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
|---|
| 48 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
|---|
| 49 | "\0\0\0\0"
|
|---|
| 50 | #define LOCALEDIR_MAX 260
|
|---|
| 51 |
|
|---|
| 52 | char *_os2_libdir = NULL;
|
|---|
| 53 | char *_os2_localealiaspath = NULL;
|
|---|
| 54 | char *_os2_localedir = NULL;
|
|---|
| 55 |
|
|---|
| 56 | static __attribute__((constructor)) void
|
|---|
| 57 | os2_initialize ()
|
|---|
| 58 | {
|
|---|
| 59 | char *root = getenv ("UNIXROOT");
|
|---|
| 60 | char *gnulocaledir = getenv ("GNULOCALEDIR");
|
|---|
| 61 |
|
|---|
| 62 | _os2_libdir = gnulocaledir;
|
|---|
| 63 | if (!_os2_libdir)
|
|---|
| 64 | {
|
|---|
| 65 | if (root)
|
|---|
| 66 | {
|
|---|
| 67 | size_t sl = strlen (root);
|
|---|
| 68 | _os2_libdir = (char *) malloc (sl + strlen (LIBDIR) + 1);
|
|---|
| 69 | memcpy (_os2_libdir, root, sl);
|
|---|
| 70 | memcpy (_os2_libdir + sl, LIBDIR, strlen (LIBDIR) + 1);
|
|---|
| 71 | }
|
|---|
| 72 | else
|
|---|
| 73 | _os2_libdir = LIBDIR;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | _os2_localealiaspath = gnulocaledir;
|
|---|
| 77 | if (!_os2_localealiaspath)
|
|---|
| 78 | {
|
|---|
| 79 | if (root)
|
|---|
| 80 | {
|
|---|
| 81 | size_t sl = strlen (root);
|
|---|
| 82 | _os2_localealiaspath = (char *) malloc (sl + strlen (LOCALE_ALIAS_PATH) + 1);
|
|---|
| 83 | memcpy (_os2_localealiaspath, root, sl);
|
|---|
| 84 | memcpy (_os2_localealiaspath + sl, LOCALE_ALIAS_PATH, strlen (LOCALE_ALIAS_PATH) + 1);
|
|---|
| 85 | }
|
|---|
| 86 | else
|
|---|
| 87 | _os2_localealiaspath = LOCALE_ALIAS_PATH;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | _os2_localedir = gnulocaledir;
|
|---|
| 91 | if (!_os2_localedir)
|
|---|
| 92 | {
|
|---|
| 93 | if (root)
|
|---|
| 94 | {
|
|---|
| 95 | size_t sl = strlen (root);
|
|---|
| 96 | _os2_localedir = (char *) malloc (sl + strlen (LOCALEDIR) + 1);
|
|---|
| 97 | memcpy (_os2_localedir, root, sl);
|
|---|
| 98 | memcpy (_os2_localedir + sl, LOCALEDIR, strlen (LOCALEDIR) + 1);
|
|---|
| 99 | }
|
|---|
| 100 | else
|
|---|
| 101 | _os2_localedir = LOCALEDIR;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | {
|
|---|
| 105 | extern const char _nl_default_dirname__[];
|
|---|
| 106 | if (strlen (_os2_localedir) <= LOCALEDIR_MAX)
|
|---|
| 107 | strcpy (_nl_default_dirname__, _os2_localedir);
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|