summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2002-03-10 08:30:15 +0000
committerAndrew Tridgell <tridge@samba.org>2002-03-10 08:30:15 +0000
commit96300f6008f964351c4d5daf7710e1692754e58d (patch)
tree2728ad8946551573748603467515247ab923f7bd
parent1975b3e4a2318ca79aacae0f03dcbc68bdaeee45 (diff)
downloadsamba-96300f6008f964351c4d5daf7710e1692754e58d.tar.gz
samba-96300f6008f964351c4d5daf7710e1692754e58d.tar.bz2
samba-96300f6008f964351c4d5daf7710e1692754e58d.zip
make tdbbackup more portable
(This used to be commit 9cc1dadfb09c2352ed188d668b02ccffaa009895)
-rw-r--r--source3/tdb/tdbbackup.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/source3/tdb/tdbbackup.c b/source3/tdb/tdbbackup.c
index ae8f143440..27cdd32835 100644
--- a/source3/tdb/tdbbackup.c
+++ b/source3/tdb/tdbbackup.c
@@ -57,6 +57,19 @@
static int failed;
+static char *add_suffix(const char *name, const char *suffix)
+{
+ char *ret;
+ int len = strlen(name) + strlen(suffix) + 1;
+ ret = malloc(len);
+ if (!ret) {
+ fprintf(stderr,"Out of memory!\n");
+ exit(1);
+ }
+ snprintf(ret, len, "%s%s", name, suffix);
+ return ret;
+}
+
static int copy_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
{
TDB_CONTEXT *tdb_new = (TDB_CONTEXT *)state;
@@ -84,11 +97,11 @@ static int backup_tdb(const char *old_name, const char *new_name)
{
TDB_CONTEXT *tdb;
TDB_CONTEXT *tdb_new;
- char *tmp_name = NULL;
+ char *tmp_name;
struct stat st;
int count1, count2;
- asprintf(&tmp_name, "%s.tmp", new_name);
+ tmp_name = add_suffix(new_name, ".tmp");
/* stat the old tdb to find its permissions */
if (stat(old_name, &st) != 0) {
@@ -253,9 +266,9 @@ static void usage(void)
for (i=0; i<argc; i++) {
const char *fname = argv[i];
- char *bak_name = NULL;
+ char *bak_name;
- asprintf(&bak_name, "%s%s", fname, suffix);
+ bak_name = add_suffix(fname, suffix);
if (verify) {
if (verify_tdb(fname, bak_name) != 0) {