lib/util use modules_path(), data_path() and shlib_ext() from source3
[sfrench/samba-autobuild/.git] / source3 / intl / lang_tdb.c
index 14b075e6d7591964a010df57ab6bda8233b32221..6070e29e5ade69209fd6fdb8ef99ff1d6a6dcbb0 100644 (file)
@@ -18,6 +18,9 @@
 */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "intl/lang_tdb.h"
+#include "util_tdb.h"
 
 static TDB_CONTEXT *tdb;
 
@@ -26,26 +29,26 @@ static char *current_lang;
 
 
 /* load a msg file into the tdb */
-static BOOL load_msg(const char *msg_file)
+static bool load_msg(const char *msg_file)
 {
        char **lines;
        int num_lines, i;
        char *msgid, *msgstr;
        TDB_DATA data;
 
-       lines = file_lines_load(msg_file, &num_lines,0);
+       lines = file_lines_load(msg_file, &num_lines, 0, NULL);
 
        if (!lines) {
                return False;
        }
 
        if (tdb_lockall(tdb) != 0) {
-               file_lines_free(lines);
+               TALLOC_FREE(lines);
                return False;
        }
 
        /* wipe the db */
-       tdb_traverse(tdb, tdb_traverse_delete_fn, NULL);
+       tdb_wipe_all(tdb);
 
        msgid = NULL;
        
@@ -68,7 +71,7 @@ static BOOL load_msg(const char *msg_file)
                }
        }
 
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
        tdb_unlockall(tdb);
 
        return True;
@@ -93,14 +96,14 @@ static const char *get_lang(void)
 
 /* initialise the message translation subsystem. If the "lang" argument
    is NULL then get the language from the normal environment variables */
-BOOL lang_tdb_init(const char *lang)
+bool lang_tdb_init(const char *lang)
 {
        char *path = NULL;
        char *msg_path = NULL;
        struct stat st;
        static int initialised;
        time_t loadtime;
-       BOOL result = False;
+       bool result = False;
 
        /* we only want to init once per process, unless given
           an override */
@@ -127,7 +130,11 @@ BOOL lang_tdb_init(const char *lang)
        if (!lang) 
                return True;
 
-       asprintf(&msg_path, "%s.msg", lib_path((const char *)lang));
+       if (asprintf(&msg_path, "%s.msg",
+                    data_path(talloc_tos(), (const char *)lang)) == -1) {
+               DEBUG(0, ("asprintf failed\n"));
+               goto done;
+       }
        if (stat(msg_path, &st) != 0) {
                /* the msg file isn't available */
                DEBUG(10, ("lang_tdb_init: %s: %s\n", msg_path, 
@@ -135,7 +142,10 @@ BOOL lang_tdb_init(const char *lang)
                goto done;
        }
        
-       asprintf(&path, "%s%s.tdb", lock_path("lang_"), lang);
+       if (asprintf(&path, "%s%s.tdb", lock_path("lang_"), lang) == -1) {
+               DEBUG(0, ("asprintf failed\n"));
+               goto done;
+       }
 
        DEBUG(10, ("lang_tdb_init: loading %s\n", path));
 
@@ -227,7 +237,7 @@ const char *lang_msg(const char *msgid)
 void lang_msg_free(const char *msgstr)
 {
        if (!tdb) return;
-       free((void *)msgstr);
+       free(discard_const_p(void, msgstr));
 }
 
 /*