}
/* initialise a new database with a specified hash size */
-static int tdb_new_database(struct tdb_context *tdb, int hash_size)
+static int tdb_new_database(struct tdb_context *tdb, struct tdb_header *header,
+ int hash_size)
{
struct tdb_header *newdb;
size_t size;
if (tdb->flags & TDB_INTERNAL) {
tdb->map_size = size;
tdb->map_ptr = (char *)newdb;
- memcpy(&tdb->header, newdb, sizeof(tdb->header));
+ memcpy(header, newdb, sizeof(*header));
/* Convert the `ondisk' version if asked. */
CONVERT(*newdb);
return 0;
/* This creates an endian-converted header, as if read from disk */
CONVERT(*newdb);
- memcpy(&tdb->header, newdb, sizeof(tdb->header));
+ memcpy(header, newdb, sizeof(*header));
/* Don't endian-convert the magic food! */
memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
if (tdb->flags & TDB_INTERNAL) {
tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP);
tdb->flags &= ~TDB_CLEAR_IF_FIRST;
- if (tdb_new_database(tdb, hash_size) != 0) {
+ if (tdb_new_database(tdb, &tdb->header, hash_size) != 0) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!"));
goto fail;
}
name, strerror(errno)));
goto fail;
}
- ret = tdb_new_database(tdb, hash_size);
+ ret = tdb_new_database(tdb, &tdb->header, hash_size);
if (ret == -1) {
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
"tdb_new_database failed for %s: %s\n",
errno = 0;
if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
|| strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) {
- if (!(open_flags & O_CREAT) || tdb_new_database(tdb, hash_size) == -1) {
+ if (!(open_flags & O_CREAT) ||
+ tdb_new_database(tdb, &tdb->header, hash_size) == -1) {
if (errno == 0) {
errno = EIO; /* ie bad format or something */
}