Fixed message typo.
[captive.git] / src / libcaptive / client / standalone.c
1 /* $Id$
2  * General + --enable-standalone optional init for static builds of captive
3  * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
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 General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "standalone.h" /* self */
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <glib-object.h>
26 #include <locale.h>
27
28
29 gboolean captive_standalone_init_done=FALSE;
30
31 void captive_standalone_init(void)
32 {
33         if (captive_standalone_init_done)
34                 return;
35
36 #ifdef ENABLE_STANDALONE
37
38         /* Prevent glibc loading: /usr/lib/gconv/gconv-modules.cache */
39         setenv("GCONV_PATH","/foobar",
40                         1);     /* overwrite */
41
42         /* Not needed: "LIBCHARSET_ALIAS_DIR"
43          * as prevented by: glib-2.6.4-noaliases.patch
44          */
45
46         /* Do not redefine the 'LANG'/'LC_*' settings to avoid corrupting
47          * filenames charset interpretation.
48          * Do not redefine the 'LOCPATH' settings as we just hope to find
49          * the right definitions - we do not supply any ourselves.
50          * Be sure the locale messages dirs are not ".utf8" suffixed:
51          * glibc-20050524T1606/locale/findlocale.c:
52          *      If the locale name contains a charset name and the charset name used in
53          *      the locale (present in the LC_CTYPE data) is not the same (after
54          *      resolving aliases etc) we reject the locale
55          */
56 #if 0
57         if (getenv("LC_ALL"))
58                 setenv("LC_MESSAGES",getenv("LC_ALL"),
59                                 1);     /* overwrite */
60         if (!getenv("LC_MESSAGES") && getenv("LANG"))
61                 setenv("LC_MESSAGES",getenv("LANG"),
62                                 1);     /* overwrite */
63         setenv("LC_CTYPE","en_US.utf8",
64                         1);     /* overwrite */
65         unsetenv("LANG");
66         unsetenv("LC_COLLATE");
67         unsetenv("LC_MONETARY");
68         unsetenv("LC_NUMERIC");
69         unsetenv("LC_TIME");
70
71         /* It may differ across distributions. Maybe - just expected. */
72         setenv("LOCPATH",LOCALEDIR,
73                         1);     /* overwrite */
74 #endif
75
76 #endif /* ENABLE_STANDALONE */
77
78         /* Prevent output block buffering if redirecting stdout to file. */
79         setvbuf(stdout,(char *)NULL,_IONBF,0);
80         setvbuf(stderr,(char *)NULL,_IONBF,0);
81
82         /* Initialize the i18n stuff */
83         setlocale(LC_ALL,"");
84         bindtextdomain(PACKAGE,LOCALEDIR);
85         textdomain(PACKAGE);
86
87         /* Initialize GObject subsystem of GLib. */
88         g_type_init();
89
90         captive_standalone_init_done=TRUE;
91 }