- if (!(tdb->flags & TDB1_NOMMAP)) {
- tdb->map_ptr = mmap(NULL, tdb->map_size,
- PROT_READ|(tdb->read_only? 0:PROT_WRITE),
- MAP_SHARED|MAP_FILE, tdb->fd, 0);
+ if (!(tdb->flags & TDB_NOMMAP)) {
+ int mmap_flags;
+ if ((tdb->open_flags & O_ACCMODE) == O_RDONLY)
+ mmap_flags = PROT_READ;
+ else
+ mmap_flags = PROT_READ | PROT_WRITE;
+
+ tdb->file->map_ptr = mmap(NULL, tdb->file->map_size,
+ mmap_flags,
+ MAP_SHARED|MAP_FILE, tdb->file->fd, 0);