summaryrefslogtreecommitdiff
path: root/c_src/filebuffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'c_src/filebuffer.c')
-rw-r--r--c_src/filebuffer.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/c_src/filebuffer.c b/c_src/filebuffer.c
index 8285695..87b9859 100644
--- a/c_src/filebuffer.c
+++ b/c_src/filebuffer.c
@@ -177,7 +177,7 @@ bf_read(buffered_file *file, uint64_t offset, size_t length, char **error)
}
buffered_file *
-bf_open(const char *path, int flags, const char *name)
+bf_open(const char *path, int flags, const char *name, int lock)
{
buffered_file *file = malloc(sizeof(buffered_file));
@@ -187,6 +187,16 @@ bf_open(const char *path, int flags, const char *name)
return NULL;
}
+ if (lock) {
+ int ret;
+
+ ret = flock(file->fd, LOCK_EX|LOCK_NB);
+ if (ret == -1) {
+ warn("flock %s", path);
+ return NULL;
+ }
+ }
+
file->name = name;
off_t datafile_filesize = lseek(file->fd, 0, SEEK_END);