[vlc-commits] bindtextdomain: cleanup and fix error handling

Rémi Denis-Courmont git at videolan.org
Mon Jan 24 17:45:46 CET 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jan 24 18:45:33 2011 +0200| [bbcc3288fbad733a2b574efc435c32a400e872b1] | committer: Rémi Denis-Courmont

bindtextdomain: cleanup and fix error handling

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bbcc3288fbad733a2b574efc435c32a400e872b1
---

 src/modules/textdomain.c |   47 +++++++++++++++++++++++----------------------
 1 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/src/modules/textdomain.c b/src/modules/textdomain.c
index 96a0072..4b5ac5b 100644
--- a/src/modules/textdomain.c
+++ b/src/modules/textdomain.c
@@ -35,30 +35,38 @@
 
 int vlc_bindtextdomain (const char *domain)
 {
-    int ret = 0;
-
 #if defined (ENABLE_NLS)
     /* Specify where to find the locales for current domain */
 # if !defined (__APPLE__) && !defined (WIN32)
     static const char path[] = LOCALEDIR;
+
+    if (bindtextdomain (domain, path) == NULL)
+    {
+        fprintf (stderr, "%s: text domain not found in %s\n", domain, path);
+        return -1;
+    }
 # else
-    char *path = config_GetDataDirDefault();
-    char *buf;
+    char *datadir = config_GetDataDirDefault();
+    if (unlikely(datadir == NULL))
+        return -1;
 
-    if (unlikely(path == NULL))
+    char *upath;
+    int ret = asprintf (&upath, "%s" DIR_SEP "locale", datadir);
+    free (datadir);
+    if (unlikely(ret == -1))
         return -1;
-    ret = asprintf (&buf, "%s" DIR_SEP "locale", path);
-    free (path);
-    path = ToLocaleDup (buf);
-    free (buf);
-# endif
 
-    if (bindtextdomain (domain, path) == NULL)
+    char *lpath = ToLocaleDup (upath);
+    if (lpath == NULL || bindtextdomain (domain, lpath) == NULL)
     {
-        fprintf (stderr, "%s: text domain not found in %s\n", domain, path);
-        ret = -1;
-        goto out;
+        free (lpath);
+        fprintf (stderr, "%s: text domain not found in %s\n", domain, upath);
+        free (upath);
+        return -1;
     }
+    free (lpath);
+    free (upath);
+# endif
 
     /* LibVLC wants all messages in UTF-8.
      * Unfortunately, we cannot ask UTF-8 for strerror_r(), strsignal_r()
@@ -69,24 +77,17 @@ int vlc_bindtextdomain (const char *domain)
         fprintf (stderr, "%s: UTF-8 encoding bot available\n", domain);
         // Unbinds the text domain to avoid broken encoding
         bindtextdomain (PACKAGE_NAME, "/DOES_NOT_EXIST");
-        ret = -1;
-        goto out;
+        return -1;
     }
 
     /* LibVLC does NOT set the default textdomain, since it is a library.
      * This could otherwise break programs using LibVLC (other than VLC).
      * textdomain (PACKAGE_NAME);
      */
-out:
-# if defined (__APPLE__) || defined (WIN32)
-    free (path);
-# endif
 
 #else /* !ENABLE_NLS */
     (void)domain;
 #endif
 
-    return ret;
+    return 0;
 }
-
-



More information about the vlc-commits mailing list