Improved invalid utf8 encoding error - g_get_charset() is now also reported.
authorlace <>
Tue, 24 Jan 2006 16:27:21 +0000 (16:27 +0000)
committerlace <>
Tue, 24 Jan 2006 16:27:21 +0000 (16:27 +0000)
src/client/fuse/utf8.c
src/client/fuse/utf8.h

index 8c0ee73..ca0b307 100644 (file)
 #include <glib/gunicode.h>
 
 
 #include <glib/gunicode.h>
 
 
-char *capfuse_filename_to_utf8_malloc_errorchecking(const char *name)
+char *capfuse_utf8_engine_malloc_errorchecking(const char *funcname,
+               gchar *(*func)(const gchar *opsysstring,gssize len,gsize *bytes_read,gsize *bytes_written,GError **error),
+               const char *string)
 {
 GError *error;
 char *r;
 
 {
 GError *error;
 char *r;
 
-       g_return_val_if_fail(name!=NULL,NULL);
+       g_return_val_if_fail(string!=NULL,NULL);
 
        error=NULL;
        r=g_filename_to_utf8(
 
        error=NULL;
        r=g_filename_to_utf8(
-                       name,   /* opsysstring */
+                       string, /* g_filename_to_utf8=>opsysstring || g_filename_from_utf8=>utf8string */
                        -1,     /* len; '\0'-terminated */
                        NULL,   /* bytes_read */
                        NULL,   /* bytes_written */
                        &error);        /* error */
                        -1,     /* len; '\0'-terminated */
                        NULL,   /* bytes_read */
                        NULL,   /* bytes_written */
                        &error);        /* error */
+       g_assert(!r==!!error);
        if (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;
+const gchar *charset=NULL;
 
                g_get_charset(&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_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,
+                               _("captive-FUSE %s(): string=\"%s\"; g_get_charset()=\"%s\": %s (see locale(7) and mount(8) environment variables)"),
+                               funcname,string,charset,error->message);
                g_clear_error(&error);
                }
        return r;
                g_clear_error(&error);
                }
        return r;
index 7df8eb9..6583051 100644 (file)
 
 
 #include <captive/macros.h>
 
 
 #include <captive/macros.h>
+#include <glib/gerror.h>
 
 
 G_BEGIN_DECLS
 
 
 
 G_BEGIN_DECLS
 
-char *capfuse_filename_to_utf8_malloc_errorchecking(const char *name);
-char *capfuse_filename_from_utf8_malloc_errorchecking(const char *name);
+char *capfuse_utf8_engine_malloc_errorchecking(const char *funcname,
+               gchar *(*func)(const gchar *opsysstring,gssize len,gsize *bytes_read,gsize *bytes_written,GError **error),
+               const char *string);
+
+#define capfuse_filename_to_utf8_malloc_errorchecking(name) \
+               capfuse_utf8_engine_malloc_errorchecking("g_filename_to_utf8",g_filename_to_utf8,(name))
+#define capfuse_filename_from_utf8_malloc_errorchecking(name) \
+               capfuse_utf8_engine_malloc_errorchecking("g_filename_from_utf8",g_filename_from_utf8,(name))
 
 #define CAPFUSE_FILENAME_TO_UTF8_ALLOCA(name) ({ \
                const char *_capfuse_filename_to_utf8_alloca_name=(name); \
 
 #define CAPFUSE_FILENAME_TO_UTF8_ALLOCA(name) ({ \
                const char *_capfuse_filename_to_utf8_alloca_name=(name); \