qulogic/libgnt
Clone
Summary
Browse
Changes
Graph
Clean up the crazy C_ function
2019-10-03, Gary Kramlich
bda6506046bb
Parents
48801da06f8c
Children
a78a89e1578b
Clean up the crazy C_ function
1 files changed, 19 insertions(+), 8 deletions(-)
+19
-8
gntmain.c
--- a/gntmain.c Thu Oct 03 03:57:52 2019 -0500
+++ b/gntmain.c Thu Oct 03 05:10:03 2019 -0500
@@ -924,23 +924,34 @@
gnt_wm_get_keypress_mode(wm) == GNT_KP_MODE_WAIT_ON_CHILD);
}
+/* to save other's time... this ugly function converts the given string to the
+ * locale if necessary and returns it as a const gchar *. Since it needs to
+ * return a const gchar * there's a bunch of messing around with a static
+ * variable. While this works, this makes this non-thread safe and who knows
+ * what else.
+ */
const char *C_(const char *x)
{
static char *c = NULL;
if (gnt_need_conversation_to_locale) {
GError *error = NULL;
- g_free(c);
- c = g_locale_from_utf8(x, -1, NULL, NULL, &error);
- if (c == NULL || error) {
- char *store = c;
- c = NULL;
+ gchar *newc = NULL;
+
+ newc = g_locale_from_utf8(x, -1, NULL, NULL, &error);
+ if(error != NULL) {
gnt_warning("Error: %s\n", error ? error->message : "(unknown)");
+
g_error_free(error);
- error = NULL;
+
+ return x;
+ }
+
+ if(newc != NULL) {
g_free(c);
- c = store;
+ c = newc;
}
- return c ? c : x;
+
+ return c != NULL ? c : x;
} else
return x;
}