Improved invalid utf8 encoding error - g_get_charset() is now also reported.
[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_utf8_engine_malloc_errorchecking(const char *funcname,
30                 gchar *(*func)(const gchar *opsysstring,gssize len,gsize *bytes_read,gsize *bytes_written,GError **error),
31                 const char *string)
32 {
33 GError *error;
34 char *r;
35
36         g_return_val_if_fail(string!=NULL,NULL);
37
38         error=NULL;
39         r=g_filename_to_utf8(
40                         string, /* g_filename_to_utf8=>opsysstring || g_filename_from_utf8=>utf8string */
41                         -1,     /* len; '\0'-terminated */
42                         NULL,   /* bytes_read */
43                         NULL,   /* bytes_written */
44                         &error);        /* error */
45         g_assert(!r==!!error);
46         if (error) {
47 const gchar *charset=NULL;
48
49                 g_get_charset(&charset);
50                 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,
51                                 _("captive-FUSE %s(): string=\"%s\"; g_get_charset()=\"%s\": %s (see locale(7) and mount(8) environment variables)"),
52                                 funcname,string,charset,error->message);
53                 g_clear_error(&error);
54                 }
55         return r;
56 }