Workaround FUSE missing the generally broken Linux kernel charset support.
[captive.git] / src / client / fuse / utf8.c
1 /* $Id$
2  * FUSE interface module utf8 conversions for libcaptive
3  * Copyright (C) 2003-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 "utf8.h"       /* self */
23 #include <glib/gmessages.h>
24 #include <glib/gerror.h>
25 #include <glib/gconvert.h>
26 #include <glib/gunicode.h>
27
28
29 char *capfuse_filename_to_utf8_malloc_errorchecking(const char *name)
30 {
31 GError *error;
32 char *r;
33
34         g_return_val_if_fail(name!=NULL,NULL);
35
36         error=NULL;
37         r=g_filename_to_utf8(
38                         name,   /* opsysstring */
39                         -1,     /* len; '\0'-terminated */
40                         NULL,   /* bytes_read */
41                         NULL,   /* bytes_written */
42                         &error);        /* error */
43         if (error) {
44                 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,
45                                 _("captive-FUSE %s(): name=\"%s\": %s (see locale(7) and mount(8) environment variables)"),
46                                 "g_filename_to_utf8",name,error->message);
47                 g_clear_error(&error);
48                 }
49         return r;
50 }
51
52
53 char *capfuse_filename_from_utf8_malloc_errorchecking(const char *name)
54 {
55 GError *error;
56 char *r;
57
58         g_return_val_if_fail(name!=NULL,NULL);
59
60         error=NULL;
61         r=g_filename_from_utf8(
62                         name,   /* utf8string */
63                         -1,     /* len; '\0'-terminated */
64                         NULL,   /* bytes_read */
65                         NULL,   /* bytes_written */
66                         &error);        /* error */
67         if (error) {
68 const gchar *charset;
69
70                 g_get_charset(&charset);
71                 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,"captive-FUSE %s(): name=\"%s\"; g_get_charset()=\"%s\", %s: %s",
72                                 "g_filename_from_utf8",name,charset,
73                                 _("see environment variables - locale(7), mount(8) and locale(1) commands \"locale\" and \"locale -a\""),
74                                 error->message);
75                 g_clear_error(&error);
76                 }
77         return r;
78 }