wscript: Add check for --wrap linker flag
[vlendec/samba-autobuild/.git] / source3 / intl / lang_tdb.c
index 6ad9ef8496b790f1d2dd7e7fbcdf8aa9d47ab897..ecdfe1dc911db693ec6673954dd9d4d87a1a3839 100644 (file)
 */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "intl/lang_tdb.h"
+#include "util_tdb.h"
+#include "lib/util/util_paths.h"
 
 static TDB_CONTEXT *tdb;
 
@@ -33,19 +37,19 @@ static bool load_msg(const char *msg_file)
        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 +72,7 @@ static bool load_msg(const char *msg_file)
                }
        }
 
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
        tdb_unlockall(tdb);
 
        return True;
@@ -100,7 +104,9 @@ bool lang_tdb_init(const char *lang)
        struct stat st;
        static int initialised;
        time_t loadtime;
-       bool result = False;
+       bool result = false;
+       char *dpath = NULL;
+       char *lpath = NULL;
 
        /* we only want to init once per process, unless given
           an override */
@@ -127,8 +133,12 @@ bool lang_tdb_init(const char *lang)
        if (!lang) 
                return True;
 
-       if (asprintf(&msg_path, "%s.msg",
-                    data_path((const char *)lang)) == -1) {
+       dpath = data_path(talloc_tos(), (const char *)lang);
+       if (dpath == NULL) {
+               goto done;
+       }
+
+       if (asprintf(&msg_path, "%s.msg", dpath) == -1) {
                DEBUG(0, ("asprintf failed\n"));
                goto done;
        }
@@ -138,8 +148,13 @@ bool lang_tdb_init(const char *lang)
                           strerror(errno)));
                goto done;
        }
-       
-       if (asprintf(&path, "%s%s.tdb", lock_path("lang_"), lang) == -1) {
+
+       lpath = lock_path("lang_");
+       if (lpath == NULL) {
+               goto done;
+       }
+
+       if (asprintf(&path, "%s%s.tdb", lpath, lang) == -1) {
                DEBUG(0, ("asprintf failed\n"));
                goto done;
        }
@@ -172,6 +187,8 @@ bool lang_tdb_init(const char *lang)
  done:
        SAFE_FREE(msg_path);
        SAFE_FREE(path);
+       TALLOC_FREE(lpath);
+       TALLOC_FREE(dpath);
 
        return result;
 }
@@ -234,7 +251,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));
 }
 
 /*