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