1 /* Message catalogs for internationalization.
2 Copyright (C) 1995-1997, 2000-2016, 2018-2020 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 <https://www.gnu.org/licenses/>. */
16
17 #ifndef _LIBINTL_H
18 #define _LIBINTL_H 1
19
20 #include <locale.h>
21 #if (defined __APPLE__ && defined __MACH__) && @HAVE_NEWLOCALE@
22 # include <xlocale.h>
23 #endif
24
25 /* The LC_MESSAGES locale category is the category used by the functions
26 gettext() and dgettext(). It is specified in POSIX, but not in ANSI C.
27 On systems that don't define it, use an arbitrary value instead.
28 On Solaris, <locale.h> defines __LOCALE_H (or _LOCALE_H in Solaris 2.5)
29 then includes <libintl.h> (i.e. this file!) and then only defines
30 LC_MESSAGES. To avoid a redefinition warning, don't define LC_MESSAGES
31 in this case. */
32 #if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun))
33 # define LC_MESSAGES 1729
34 #endif
35
36 /* We define an additional symbol to signal that we use the GNU
37 implementation of gettext. */
38 #define __USE_GNU_GETTEXT 1
39
40 /* Provide information about the supported file formats. Returns the
41 maximum minor revision number supported for a given major revision. */
42 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) \
43 ((major) == 0 || (major) == 1 ? 1 : -1)
44
45 /* Resolve a platform specific conflict on DJGPP. GNU gettext takes
46 precedence over _conio_gettext. */
47 #ifdef __DJGPP__
48 # undef gettext
49 #endif
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55
56 /* Version number: (major<<16) + (minor<<8) + subminor */
57 #define LIBINTL_VERSION 0x001500
58 extern int libintl_version;
59
60
61 /* We redirect the functions to those prefixed with "libintl_". This is
62 necessary, because some systems define gettext/textdomain/... in the C
63 library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer).
64 If we used the unprefixed names, there would be cases where the
65 definition in the C library would override the one in the libintl.so
66 shared library. Recall that on ELF systems, the symbols are looked
67 up in the following order:
68 1. in the executable,
69 2. in the shared libraries specified on the link command line, in order,
70 3. in the dependencies of the shared libraries specified on the link
71 command line,
72 4. in the dlopen()ed shared libraries, in the order in which they were
73 dlopen()ed.
74 The definition in the C library would override the one in libintl.so if
75 either
76 * -lc is given on the link command line and -lintl isn't, or
77 * -lc is given on the link command line before -lintl, or
78 * libintl.so is a dependency of a dlopen()ed shared library but not
79 linked to the executable at link time.
80 Since Solaris gettext() behaves differently than GNU gettext(), this
81 would be unacceptable.
82
83 The redirection happens by default through macros in C, so that &gettext
84 is independent of the compilation unit, but through inline functions in
85 C++, in order not to interfere with the name mangling of class fields or
86 class methods called 'gettext'. */
87
88 /* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS.
89 If he doesn't, we choose the method. A third possible method is
90 _INTL_REDIRECT_ASM, supported only by GCC. */
91 #if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS)
92 # if defined __GNUC__ && __GNUC__ >= 2 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1) && !defined __MINGW32__ && !(__GNUC__ == 2 && defined _AIX) && (defined __STDC__ || defined __cplusplus)
93 # define _INTL_REDIRECT_ASM
94 # else
95 # ifdef __cplusplus
96 # define _INTL_REDIRECT_INLINE
97 # else
98 # define _INTL_REDIRECT_MACROS
99 # endif
100 # endif
101 #endif
102 /* Auxiliary macros. */
103 #ifdef _INTL_REDIRECT_ASM
104 # define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname))
105 # define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring
106 # define _INTL_STRINGIFY(prefix) #prefix
107 #else
108 # define _INTL_ASM(cname)
109 #endif
110
111 /* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return
112 its n-th argument literally. This enables GCC to warn for example about
113 printf (gettext ("foo %y")). */
114 #if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1 && !(defined __clang__ && __clang__ && __clang_major__ >= 3) && defined __cplusplus)
115 # define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n)))
116 #else
117 # define _INTL_MAY_RETURN_STRING_ARG(n)
118 #endif
119
120 /* Look up MSGID in the current default message catalog for the current
121 LC_MESSAGES locale. If not found, returns MSGID itself (the default
122 text). */
123 #ifdef _INTL_REDIRECT_INLINE
124 extern char *libintl_gettext (const char *__msgid)
125 _INTL_MAY_RETURN_STRING_ARG (1);
126 static inline
127 _INTL_MAY_RETURN_STRING_ARG (1)
gettext(const char * __msgid)128 char *gettext (const char *__msgid)
129 {
130 return libintl_gettext (__msgid);
131 }
132 #else
133 #ifdef _INTL_REDIRECT_MACROS
134 # define gettext libintl_gettext
135 #endif
136 extern char *gettext (const char *__msgid)
137 _INTL_ASM (libintl_gettext)
138 _INTL_MAY_RETURN_STRING_ARG (1);
139 #endif
140
141 /* Look up MSGID in the DOMAINNAME message catalog for the current
142 LC_MESSAGES locale. */
143 #ifdef _INTL_REDIRECT_INLINE
144 extern char *libintl_dgettext (const char *__domainname, const char *__msgid)
145 _INTL_MAY_RETURN_STRING_ARG (2);
146 static inline
147 _INTL_MAY_RETURN_STRING_ARG (2)
dgettext(const char * __domainname,const char * __msgid)148 char *dgettext (const char *__domainname, const char *__msgid)
149 {
150 return libintl_dgettext (__domainname, __msgid);
151 }
152 #else
153 #ifdef _INTL_REDIRECT_MACROS
154 # define dgettext libintl_dgettext
155 #endif
156 extern char *dgettext (const char *__domainname, const char *__msgid)
157 _INTL_ASM (libintl_dgettext)
158 _INTL_MAY_RETURN_STRING_ARG (2);
159 #endif
160
161 /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
162 locale. */
163 #ifdef _INTL_REDIRECT_INLINE
164 extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
165 int __category)
166 _INTL_MAY_RETURN_STRING_ARG (2);
167 static inline
168 _INTL_MAY_RETURN_STRING_ARG (2)
dcgettext(const char * __domainname,const char * __msgid,int __category)169 char *dcgettext (const char *__domainname, const char *__msgid, int __category)
170 {
171 return libintl_dcgettext (__domainname, __msgid, __category);
172 }
173 #else
174 #ifdef _INTL_REDIRECT_MACROS
175 # define dcgettext libintl_dcgettext
176 #endif
177 extern char *dcgettext (const char *__domainname, const char *__msgid,
178 int __category)
179 _INTL_ASM (libintl_dcgettext)
180 _INTL_MAY_RETURN_STRING_ARG (2);
181 #endif
182
183
184 /* Similar to 'gettext' but select the plural form corresponding to the
185 number N. */
186 #ifdef _INTL_REDIRECT_INLINE
187 extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
188 unsigned long int __n)
189 _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
190 static inline
191 _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2)
ngettext(const char * __msgid1,const char * __msgid2,unsigned long int __n)192 char *ngettext (const char *__msgid1, const char *__msgid2,
193 unsigned long int __n)
194 {
195 return libintl_ngettext (__msgid1, __msgid2, __n);
196 }
197 #else
198 #ifdef _INTL_REDIRECT_MACROS
199 # define ngettext libintl_ngettext
200 #endif
201 extern char *ngettext (const char *__msgid1, const char *__msgid2,
202 unsigned long int __n)
203 _INTL_ASM (libintl_ngettext)
204 _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
205 #endif
206
207 /* Similar to 'dgettext' but select the plural form corresponding to the
208 number N. */
209 #ifdef _INTL_REDIRECT_INLINE
210 extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
211 const char *__msgid2, unsigned long int __n)
212 _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
213 static inline
214 _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
dngettext(const char * __domainname,const char * __msgid1,const char * __msgid2,unsigned long int __n)215 char *dngettext (const char *__domainname, const char *__msgid1,
216 const char *__msgid2, unsigned long int __n)
217 {
218 return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
219 }
220 #else
221 #ifdef _INTL_REDIRECT_MACROS
222 # define dngettext libintl_dngettext
223 #endif
224 extern char *dngettext (const char *__domainname,
225 const char *__msgid1, const char *__msgid2,
226 unsigned long int __n)
227 _INTL_ASM (libintl_dngettext)
228 _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
229 #endif
230
231 /* Similar to 'dcgettext' but select the plural form corresponding to the
232 number N. */
233 #ifdef _INTL_REDIRECT_INLINE
234 extern char *libintl_dcngettext (const char *__domainname,
235 const char *__msgid1, const char *__msgid2,
236 unsigned long int __n, int __category)
237 _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
238 static inline
239 _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
dcngettext(const char * __domainname,const char * __msgid1,const char * __msgid2,unsigned long int __n,int __category)240 char *dcngettext (const char *__domainname,
241 const char *__msgid1, const char *__msgid2,
242 unsigned long int __n, int __category)
243 {
244 return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
245 }
246 #else
247 #ifdef _INTL_REDIRECT_MACROS
248 # define dcngettext libintl_dcngettext
249 #endif
250 extern char *dcngettext (const char *__domainname,
251 const char *__msgid1, const char *__msgid2,
252 unsigned long int __n, int __category)
253 _INTL_ASM (libintl_dcngettext)
254 _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
255 #endif
256
257
258 #ifndef IN_LIBGLOCALE
259
260 /* Set the current default message catalog to DOMAINNAME.
261 If DOMAINNAME is null, return the current default.
262 If DOMAINNAME is "", reset to the default of "messages". */
263 #ifdef _INTL_REDIRECT_INLINE
264 extern char *libintl_textdomain (const char *__domainname);
textdomain(const char * __domainname)265 static inline char *textdomain (const char *__domainname)
266 {
267 return libintl_textdomain (__domainname);
268 }
269 #else
270 #ifdef _INTL_REDIRECT_MACROS
271 # define textdomain libintl_textdomain
272 #endif
273 extern char *textdomain (const char *__domainname)
274 _INTL_ASM (libintl_textdomain);
275 #endif
276
277 /* Specify that the DOMAINNAME message catalog will be found
278 in DIRNAME rather than in the system locale data base. */
279 #ifdef _INTL_REDIRECT_INLINE
280 extern char *libintl_bindtextdomain (const char *__domainname,
281 const char *__dirname);
bindtextdomain(const char * __domainname,const char * __dirname)282 static inline char *bindtextdomain (const char *__domainname,
283 const char *__dirname)
284 {
285 return libintl_bindtextdomain (__domainname, __dirname);
286 }
287 #else
288 #ifdef _INTL_REDIRECT_MACROS
289 # define bindtextdomain libintl_bindtextdomain
290 #endif
291 extern char *bindtextdomain (const char *__domainname, const char *__dirname)
292 _INTL_ASM (libintl_bindtextdomain);
293 #endif
294
295 #if defined _WIN32 && !defined __CYGWIN__
296 /* Specify that the DOMAINNAME message catalog will be found
297 in WDIRNAME rather than in the system locale data base. */
298 #ifdef _INTL_REDIRECT_INLINE
299 extern wchar_t *libintl_wbindtextdomain (const char *__domainname,
300 const wchar_t *__wdirname);
wbindtextdomain(const char * __domainname,const wchar_t * __wdirname)301 static inline wchar_t *wbindtextdomain (const char *__domainname,
302 const wchar_t *__wdirname)
303 {
304 return libintl_wbindtextdomain (__domainname, __wdirname);
305 }
306 #else
307 #ifdef _INTL_REDIRECT_MACROS
308 # define wbindtextdomain libintl_wbindtextdomain
309 #endif
310 extern wchar_t *wbindtextdomain (const char *__domainname,
311 const wchar_t *__wdirname)
312 _INTL_ASM (libintl_wbindtextdomain);
313 #endif
314 #endif
315
316 /* Specify the character encoding in which the messages from the
317 DOMAINNAME message catalog will be returned. */
318 #ifdef _INTL_REDIRECT_INLINE
319 extern char *libintl_bind_textdomain_codeset (const char *__domainname,
320 const char *__codeset);
bind_textdomain_codeset(const char * __domainname,const char * __codeset)321 static inline char *bind_textdomain_codeset (const char *__domainname,
322 const char *__codeset)
323 {
324 return libintl_bind_textdomain_codeset (__domainname, __codeset);
325 }
326 #else
327 #ifdef _INTL_REDIRECT_MACROS
328 # define bind_textdomain_codeset libintl_bind_textdomain_codeset
329 #endif
330 extern char *bind_textdomain_codeset (const char *__domainname,
331 const char *__codeset)
332 _INTL_ASM (libintl_bind_textdomain_codeset);
333 #endif
334
335 #endif /* IN_LIBGLOCALE */
336
337
338 /* Support for format strings with positions in *printf(), following the
339 POSIX/XSI specification.
340 Note: These replacements for the *printf() functions are visible only
341 in source files that #include <libintl.h> or #include "gettext.h".
342 Packages that use *printf() in source files that don't refer to _()
343 or gettext() but for which the format string could be the return value
344 of _() or gettext() need to add this #include. Oh well. */
345
346 #if !@HAVE_POSIX_PRINTF@
347
348 #include <stdio.h>
349 #include <stddef.h>
350
351 /* Get va_list. */
352 #if (defined __STDC__ && __STDC__) || defined __cplusplus || defined _MSC_VER
353 # include <stdarg.h>
354 #else
355 # include <varargs.h>
356 #endif
357
358 #if !(defined fprintf && defined _GL_STDIO_H) /* don't override gnulib */
359 #undef fprintf
360 #define fprintf libintl_fprintf
361 extern int fprintf (FILE *, const char *, ...);
362 #endif
363 #if !(defined vfprintf && defined _GL_STDIO_H) /* don't override gnulib */
364 #undef vfprintf
365 #define vfprintf libintl_vfprintf
366 extern int vfprintf (FILE *, const char *, va_list);
367 #endif
368
369 #if !(defined printf && defined _GL_STDIO_H) /* don't override gnulib */
370 #undef printf
371 #if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__
372 /* Don't break __attribute__((format(printf,M,N))).
373 This redefinition is only possible because the libc in NetBSD, Cygwin,
374 mingw does not have a function __printf__.
375 Alternatively, we could have done this redirection only when compiling with
376 __GNUC__, together with a symbol redirection:
377 extern int printf (const char *, ...)
378 __asm__ (#__USER_LABEL_PREFIX__ "libintl_printf");
379 But doing it now would introduce a binary incompatibility with already
380 distributed versions of libintl on these systems. */
381 # define libintl_printf __printf__
382 #endif
383 #define printf libintl_printf
384 extern int printf (const char *, ...);
385 #endif
386 #if !(defined vprintf && defined _GL_STDIO_H) /* don't override gnulib */
387 #undef vprintf
388 #define vprintf libintl_vprintf
389 extern int vprintf (const char *, va_list);
390 #endif
391
392 #if !(defined sprintf && defined _GL_STDIO_H) /* don't override gnulib */
393 #undef sprintf
394 #define sprintf libintl_sprintf
395 extern int sprintf (char *, const char *, ...);
396 #endif
397 #if !(defined vsprintf && defined _GL_STDIO_H) /* don't override gnulib */
398 #undef vsprintf
399 #define vsprintf libintl_vsprintf
400 extern int vsprintf (char *, const char *, va_list);
401 #endif
402
403 #if @HAVE_SNPRINTF@
404
405 #if !(defined snprintf && defined _GL_STDIO_H) /* don't override gnulib */
406 #undef snprintf
407 #define snprintf libintl_snprintf
408 extern int snprintf (char *, size_t, const char *, ...);
409 #endif
410 #if !(defined vsnprintf && defined _GL_STDIO_H) /* don't override gnulib */
411 #undef vsnprintf
412 #define vsnprintf libintl_vsnprintf
413 extern int vsnprintf (char *, size_t, const char *, va_list);
414 #endif
415
416 #endif
417
418 #if @HAVE_ASPRINTF@
419
420 #if !(defined asprintf && defined _GL_STDIO_H) /* don't override gnulib */
421 #undef asprintf
422 #define asprintf libintl_asprintf
423 extern int asprintf (char **, const char *, ...);
424 #endif
425 #if !(defined vasprintf && defined _GL_STDIO_H) /* don't override gnulib */
426 #undef vasprintf
427 #define vasprintf libintl_vasprintf
428 extern int vasprintf (char **, const char *, va_list);
429 #endif
430
431 #endif
432
433 #if @HAVE_WPRINTF@
434
435 #undef fwprintf
436 #define fwprintf libintl_fwprintf
437 extern int fwprintf (FILE *, const wchar_t *, ...);
438 #undef vfwprintf
439 #define vfwprintf libintl_vfwprintf
440 extern int vfwprintf (FILE *, const wchar_t *, va_list);
441
442 #undef wprintf
443 #define wprintf libintl_wprintf
444 extern int wprintf (const wchar_t *, ...);
445 #undef vwprintf
446 #define vwprintf libintl_vwprintf
447 extern int vwprintf (const wchar_t *, va_list);
448
449 #undef swprintf
450 #define swprintf libintl_swprintf
451 extern int swprintf (wchar_t *, size_t, const wchar_t *, ...);
452 #undef vswprintf
453 #define vswprintf libintl_vswprintf
454 extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list);
455
456 #endif
457
458 #endif
459
460
461 /* Support for retrieving the name of a locale_t object. */
462 #if @HAVE_NAMELESS_LOCALES@
463
464 #ifndef GNULIB_defined_newlocale /* don't override gnulib */
465 #undef newlocale
466 #define newlocale libintl_newlocale
467 extern locale_t newlocale (int, const char *, locale_t);
468 #endif
469
470 #ifndef GNULIB_defined_duplocale /* don't override gnulib */
471 #undef duplocale
472 #define duplocale libintl_duplocale
473 extern locale_t duplocale (locale_t);
474 #endif
475
476 #ifndef GNULIB_defined_freelocale /* don't override gnulib */
477 #undef freelocale
478 #define freelocale libintl_freelocale
479 extern void freelocale (locale_t);
480 #endif
481
482 #endif
483
484
485 /* Support for the locale chosen by the user. */
486 #if (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __CYGWIN__
487
488 #ifndef GNULIB_defined_setlocale /* don't override gnulib */
489 #undef setlocale
490 #define setlocale libintl_setlocale
491 extern char *setlocale (int, const char *);
492 #endif
493
494 #if @HAVE_NEWLOCALE@
495
496 #undef newlocale
497 #define newlocale libintl_newlocale
498 /* Declare newlocale() only if the system headers define the 'locale_t' type. */
499 #if !(defined __CYGWIN__ && !defined LC_ALL_MASK)
500 extern locale_t newlocale (int, const char *, locale_t);
501 #endif
502
503 #endif
504
505 #endif
506
507
508 /* Support for relocatable packages. */
509
510 /* Sets the original and the current installation prefix of the package.
511 Relocation simply replaces a pathname starting with the original prefix
512 by the corresponding pathname with the current prefix instead. Both
513 prefixes should be directory names without trailing slash (i.e. use ""
514 instead of "/"). */
515 #define libintl_set_relocation_prefix libintl_set_relocation_prefix
516 extern void
517 libintl_set_relocation_prefix (const char *orig_prefix,
518 const char *curr_prefix);
519
520
521 #ifdef __cplusplus
522 }
523 #endif
524
525 #endif /* libintl.h */
526