2 * Nasty preload hack to allow message catalogs to be read from the build tree.
4 * export LD_PRELOAD=/usr/lib/help2man/bindtextdomain.so
5 * export TEXTDOMAIN=program
6 * export LOCALEDIR=${DESTDIR}/usr/share/locale
8 * Copyright (C) 2012 Free Software Foundation, Inc.
10 * Copying and distribution of this file, with or without modification,
11 * are permitted in any medium without royalty provided the copyright
12 * notice and this notice are preserved. This file is offered as-is,
13 * without any warranty.
15 * Written by Brendan O'Dea <bod@debian.org>
25 #define PRELOAD "bindtextdomain.so"
27 static void die(char const *msg)
29 fprintf(stderr, PRELOAD ": %s\n", msg);
33 static char *e_textdomain = 0;
34 static char *e_localedir = 0;
35 static char *(*r_textdomain)(char const *) = 0;
36 static char *(*r_bindtextdomain)(char const *, char const *) = 0;
37 static char *(*r_bind_textdomain_codeset)(char const *, char const *) = 0;
45 if (!(e_textdomain = getenv("TEXTDOMAIN")))
46 die("TEXTDOMAIN not set");
48 if (!(e_localedir = getenv("LOCALEDIR")))
49 die("LOCALEDIR not set");
51 if (!(r_textdomain = dlsym(RTLD_NEXT, "textdomain")))
52 die("can't find symbol \"textdomain\"");
54 if (!(r_bindtextdomain = dlsym(RTLD_NEXT, "bindtextdomain")))
55 die("can't find symbol \"bindtextdomain\"");
57 if (!(r_bind_textdomain_codeset = dlsym(RTLD_NEXT,
58 "bind_textdomain_codeset")))
59 die("can't find symbol \"bind_textdomain_codeset\"");
62 char *textdomain(char const *domainname)
66 r = r_textdomain(domainname);
67 if (domainname && !strcmp(domainname, e_textdomain))
68 r_bindtextdomain(domainname, e_localedir);
73 char *bindtextdomain(char const *domainname, char const *dirname)
75 char const *dir = dirname;
77 if (domainname && !strcmp(domainname, e_textdomain))
80 return r_bindtextdomain(domainname, dir);
83 char *bind_textdomain_codeset(char const *domainname, char const *codeset)
87 r = r_bind_textdomain_codeset(domainname, codeset);
88 if (domainname && !strcmp(domainname, e_textdomain))
89 r_bindtextdomain(domainname, e_localedir);