From 8bd11c0abf785313487540b87c27f0c8358451d6 Mon Sep 17 00:00:00 2001 From: lace <> Date: Tue, 24 Jan 2006 16:27:21 +0000 Subject: [PATCH] Improved invalid utf8 encoding error - g_get_charset() is now also reported. --- src/client/fuse/utf8.c | 42 ++++++++++-------------------------------- src/client/fuse/utf8.h | 11 +++++++++-- 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/src/client/fuse/utf8.c b/src/client/fuse/utf8.c index 8c0ee73..ca0b307 100644 --- a/src/client/fuse/utf8.c +++ b/src/client/fuse/utf8.c @@ -26,52 +26,30 @@ #include -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; - g_return_val_if_fail(name!=NULL,NULL); + g_return_val_if_fail(string!=NULL,NULL); 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 */ + g_assert(!r==!!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_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; diff --git a/src/client/fuse/utf8.h b/src/client/fuse/utf8.h index 7df8eb9..6583051 100644 --- a/src/client/fuse/utf8.h +++ b/src/client/fuse/utf8.h @@ -22,12 +22,19 @@ #include +#include 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); \ -- 1.8.3.1