From 3f99fc16a0a3aead82cf8cdfb9703f8f18388623 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 5 Dec 2011 17:04:30 +1030 Subject: tdb2: provide tdb_layout_write() rather than implying it by new_tdb_layout arg. Neater API. Signed-off-by: Rusty Russell (Imported from CCAN commit 79d603a5f73dfbb655d8d08f67eecb5f2da542d5) --- lib/tdb2/test/layout.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'lib/tdb2/test/layout.c') diff --git a/lib/tdb2/test/layout.c b/lib/tdb2/test/layout.c index 95cca6a810..6c601ddb85 100644 --- a/lib/tdb2/test/layout.c +++ b/lib/tdb2/test/layout.c @@ -6,10 +6,9 @@ #include #include "logging.h" -struct tdb_layout *new_tdb_layout(const char *filename) +struct tdb_layout *new_tdb_layout(void) { struct tdb_layout *layout = malloc(sizeof(*layout)); - layout->filename = filename; layout->num_elems = 0; layout->elem = NULL; return layout; @@ -314,26 +313,25 @@ struct tdb_context *tdb_layout_get(struct tdb_layout *layout, } tdb->tdb2.ftable_off = find_ftable(layout, 0)->base.off; - - /* Get physical if they asked for it. */ - if (layout->filename) { - int fd = open(layout->filename, O_WRONLY|O_TRUNC|O_CREAT, - 0600); - if (fd < 0) - err(1, "opening %s for writing", layout->filename); - if (write(fd, tdb->file->map_ptr, tdb->file->map_size) - != tdb->file->map_size) - err(1, "writing %s", layout->filename); - close(fd); - tdb_close(tdb); - /* NOMMAP is for lockcheck. */ - tdb = tdb_open(layout->filename, TDB_NOMMAP, O_RDWR, 0, - &tap_log_attr); - } - return tdb; } +void tdb_layout_write(struct tdb_layout *layout, union tdb_attribute *attr, + const char *filename) +{ + struct tdb_context *tdb = tdb_layout_get(layout, attr); + int fd; + + fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0600); + if (fd < 0) + err(1, "opening %s for writing", filename); + if (write(fd, tdb->file->map_ptr, tdb->file->map_size) + != tdb->file->map_size) + err(1, "writing %s", filename); + close(fd); + tdb_close(tdb); +} + void tdb_layout_free(struct tdb_layout *layout) { unsigned int i; -- cgit