- /* If this fails, we try to fill anyway. */
- if (ftruncate(tdb->fd, size+addition))
- ;
-
- /* now fill the file with something. This ensures that the
- file isn't sparse, which would be very bad if we ran out of
- disk. This must be done with write, not via mmap */
- memset(buf, 0x43, sizeof(buf));
- return fill(tdb, buf, sizeof(buf), addition, size);
-}
-
-const void *tdb_access_read(struct tdb_context *tdb,
- tdb_off_t off, tdb_len_t len)
-{
- const void *ret = tdb_direct(tdb, off, len);
-
- if (!ret)
- ret = tdb_alloc_read(tdb, off, len);
- return ret;
-}
-
-void tdb_access_release(struct tdb_context *tdb, const void *p)
-{
- if (!tdb->map_ptr
- || (char *)p < (char *)tdb->map_ptr
- || (char *)p >= (char *)tdb->map_ptr + tdb->map_size)
- free((void *)p);
-}
-
-#if 0
-/* write a lump of data at a specified offset */
-static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
- const void *buf, tdb_len_t len)
-{
- if (len == 0) {
- return 0;
- }
-
- if (tdb->read_only || tdb->traverse_read) {
- tdb->ecode = TDB_ERR_RDONLY;
- return -1;
- }
+ if (tdb->flags & TDB_INTERNAL) {
+ char *new = realloc(tdb->map_ptr, tdb->map_size + addition);
+ if (!new) {
+ tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+ "No memory to expand database");
+ return -1;
+ }
+ tdb->map_ptr = new;
+ tdb->map_size += addition;
+ } else {
+ /* Unmap before trying to write; old TDB claimed OpenBSD had
+ * problem with this otherwise. */
+ tdb_munmap(tdb);