1 /* $NetBSD: intl-compat.c,v 1.1.1.1 2016/01/10 21:36:17 christos Exp $ */ 2 3 /* intl-compat.c - Stub functions to call gettext functions from GNU gettext 4 Library. 5 Copyright (C) 1995, 2000, 2001 Software Foundation, Inc. 6 7 This program is free software; you can redistribute it and/or modify it 8 under the terms of the GNU Library General Public License as published 9 by the Free Software Foundation; either version 2, or (at your option) 10 any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Library General Public License for more details. 16 17 You should have received a copy of the GNU Library General Public 18 License along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 20 USA. */ 21 22 #ifdef HAVE_CONFIG_H 23 # include <config.h> 24 #endif 25 26 #include "libgnuintl.h" 27 #include "gettextP.h" 28 29 /* @@ end of prolog @@ */ 30 31 /* This file redirects the gettext functions (without prefix or suffix) to 32 those defined in the included GNU gettext library (with "__" suffix). 33 It is compiled into libintl when the included GNU gettext library is 34 configured --with-included-gettext. 35 36 This redirection works also in the case that the system C library or 37 the system libintl library contain gettext/textdomain/... functions. 38 If it didn't, we would need to add preprocessor level redirections to 39 libgnuintl.h of the following form: 40 41 # define gettext gettext__ 42 # define dgettext dgettext__ 43 # define dcgettext dcgettext__ 44 # define ngettext ngettext__ 45 # define dngettext dngettext__ 46 # define dcngettext dcngettext__ 47 # define textdomain textdomain__ 48 # define bindtextdomain bindtextdomain__ 49 # define bind_textdomain_codeset bind_textdomain_codeset__ 50 51 How does this redirection work? There are two cases. 52 A. When libintl.a is linked into an executable, it works because 53 functions defined in the executable always override functions in 54 the shared libraries. 55 B. When libintl.so is used, it works because 56 1. those systems defining gettext/textdomain/... in the C library 57 (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer) are 58 ELF systems and define these symbols as weak, thus explicitly 59 letting other shared libraries override it. 60 2. those systems defining gettext/textdomain/... in a standalone 61 libintl.so library (namely, Solaris 2.3 and newer) have this 62 shared library in /usr/lib, and the linker will search /usr/lib 63 *after* the directory where the GNU gettext library is installed. 64 65 A third case, namely when libintl.a is linked into a shared library 66 whose name is not libintl.so, is not supported. In this case, on 67 Solaris, when -lintl precedes the linker option for the shared library 68 containing GNU gettext, the system's gettext would indeed override 69 the GNU gettext. Anyone doing this kind of stuff must be clever enough 70 to 1. compile libintl.a with -fPIC, 2. remove -lintl from his linker 71 command line. */ 72 73 74 #undef gettext 75 #undef dgettext 76 #undef dcgettext 77 #undef ngettext 78 #undef dngettext 79 #undef dcngettext 80 #undef textdomain 81 #undef bindtextdomain 82 #undef bind_textdomain_codeset 83 84 85 char * 86 gettext (msgid) 87 const char *msgid; 88 { 89 return gettext__ (msgid); 90 } 91 92 93 char * 94 dgettext (domainname, msgid) 95 const char *domainname; 96 const char *msgid; 97 { 98 return dgettext__ (domainname, msgid); 99 } 100 101 102 char * 103 dcgettext (domainname, msgid, category) 104 const char *domainname; 105 const char *msgid; 106 int category; 107 { 108 return dcgettext__ (domainname, msgid, category); 109 } 110 111 112 char * 113 ngettext (msgid1, msgid2, n) 114 const char *msgid1; 115 const char *msgid2; 116 unsigned long int n; 117 { 118 return ngettext__ (msgid1, msgid2, n); 119 } 120 121 122 char * 123 dngettext (domainname, msgid1, msgid2, n) 124 const char *domainname; 125 const char *msgid1; 126 const char *msgid2; 127 unsigned long int n; 128 { 129 return dngettext__ (domainname, msgid1, msgid2, n); 130 } 131 132 133 char * 134 dcngettext (domainname, msgid1, msgid2, n, category) 135 const char *domainname; 136 const char *msgid1; 137 const char *msgid2; 138 unsigned long int n; 139 int category; 140 { 141 return dcngettext__ (domainname, msgid1, msgid2, n, category); 142 } 143 144 145 char * 146 textdomain (domainname) 147 const char *domainname; 148 { 149 return textdomain__ (domainname); 150 } 151 152 153 char * 154 bindtextdomain (domainname, dirname) 155 const char *domainname; 156 const char *dirname; 157 { 158 return bindtextdomain__ (domainname, dirname); 159 } 160 161 162 char * 163 bind_textdomain_codeset (domainname, codeset) 164 const char *domainname; 165 const char *codeset; 166 { 167 return bind_textdomain_codeset__ (domainname, codeset); 168 } 169