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