1 /* OS/2 compatibility functions.
2    Copyright (C) 2001-2002, 2015-2016 Free Software Foundation, Inc.
3 
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU Lesser General Public License as published by
6    the Free Software Foundation; either version 2.1 of the License, or
7    (at your option) 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
12    GNU Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16 
17 #define OS2_AWARE
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21 
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/param.h>
25 
26 /* A version of getenv() that works from DLLs */
27 extern unsigned long DosScanEnv (const unsigned char *pszName, unsigned char **ppszValue);
28 
29 char *
_nl_getenv(const char * name)30 _nl_getenv (const char *name)
31 {
32   unsigned char *value;
33   if (DosScanEnv (name, &value))
34     return NULL;
35   else
36     return value;
37 }
38 
39 /* A fixed size buffer.  */
40 char libintl_nl_default_dirname[MAXPATHLEN+1];
41 
42 char *_nlos2_libdir = NULL;
43 char *_nlos2_localealiaspath = NULL;
44 char *_nlos2_localedir = NULL;
45 
46 static __attribute__((constructor)) void
nlos2_initialize()47 nlos2_initialize ()
48 {
49   char *root = getenv ("UNIXROOT");
50   char *gnulocaledir = getenv ("GNULOCALEDIR");
51 
52   _nlos2_libdir = gnulocaledir;
53   if (!_nlos2_libdir)
54     {
55       if (root)
56         {
57           size_t sl = strlen (root);
58           _nlos2_libdir = (char *) malloc (sl + strlen (LIBDIR) + 1);
59           memcpy (_nlos2_libdir, root, sl);
60           memcpy (_nlos2_libdir + sl, LIBDIR, strlen (LIBDIR) + 1);
61         }
62       else
63         _nlos2_libdir = LIBDIR;
64     }
65 
66   _nlos2_localealiaspath = gnulocaledir;
67   if (!_nlos2_localealiaspath)
68     {
69       if (root)
70         {
71           size_t sl = strlen (root);
72           _nlos2_localealiaspath = (char *) malloc (sl + strlen (LOCALE_ALIAS_PATH) + 1);
73           memcpy (_nlos2_localealiaspath, root, sl);
74           memcpy (_nlos2_localealiaspath + sl, LOCALE_ALIAS_PATH, strlen (LOCALE_ALIAS_PATH) + 1);
75         }
76      else
77         _nlos2_localealiaspath = LOCALE_ALIAS_PATH;
78     }
79 
80   _nlos2_localedir = gnulocaledir;
81   if (!_nlos2_localedir)
82     {
83       if (root)
84         {
85           size_t sl = strlen (root);
86           _nlos2_localedir = (char *) malloc (sl + strlen (LOCALEDIR) + 1);
87           memcpy (_nlos2_localedir, root, sl);
88           memcpy (_nlos2_localedir + sl, LOCALEDIR, strlen (LOCALEDIR) + 1);
89         }
90       else
91         _nlos2_localedir = LOCALEDIR;
92     }
93 
94   if (strlen (_nlos2_localedir) <= MAXPATHLEN)
95     strcpy (libintl_nl_default_dirname, _nlos2_localedir);
96 }
97