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