Workaround FUSE missing the generally broken Linux kernel charset support.
[captive.git] / src / client / fuse / utf8.c
diff --git a/src/client/fuse/utf8.c b/src/client/fuse/utf8.c
new file mode 100644 (file)
index 0000000..8c0ee73
--- /dev/null
@@ -0,0 +1,78 @@
+/* $Id$
+ * FUSE interface module utf8 conversions for libcaptive
+ * Copyright (C) 2003-2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include "utf8.h"      /* self */
+#include <glib/gmessages.h>
+#include <glib/gerror.h>
+#include <glib/gconvert.h>
+#include <glib/gunicode.h>
+
+
+char *capfuse_filename_to_utf8_malloc_errorchecking(const char *name)
+{
+GError *error;
+char *r;
+
+       g_return_val_if_fail(name!=NULL,NULL);
+
+       error=NULL;
+       r=g_filename_to_utf8(
+                       name,   /* opsysstring */
+                       -1,     /* len; '\0'-terminated */
+                       NULL,   /* bytes_read */
+                       NULL,   /* bytes_written */
+                       &error);        /* error */
+       if (error) {
+               g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,
+                               _("captive-FUSE %s(): name=\"%s\": %s (see locale(7) and mount(8) environment variables)"),
+                               "g_filename_to_utf8",name,error->message);
+               g_clear_error(&error);
+               }
+       return r;
+}
+
+
+char *capfuse_filename_from_utf8_malloc_errorchecking(const char *name)
+{
+GError *error;
+char *r;
+
+       g_return_val_if_fail(name!=NULL,NULL);
+
+       error=NULL;
+       r=g_filename_from_utf8(
+                       name,   /* utf8string */
+                       -1,     /* len; '\0'-terminated */
+                       NULL,   /* bytes_read */
+                       NULL,   /* bytes_written */
+                       &error);        /* error */
+       if (error) {
+const gchar *charset;
+
+               g_get_charset(&charset);
+               g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,"captive-FUSE %s(): name=\"%s\"; g_get_charset()=\"%s\", %s: %s",
+                               "g_filename_from_utf8",name,charset,
+                               _("see environment variables - locale(7), mount(8) and locale(1) commands \"locale\" and \"locale -a\""),
+                               error->message);
+               g_clear_error(&error);
+               }
+       return r;
+}