Skip to content

Commit 57e5a9b

Browse files
authored
Merge pull request #511 from yvxiang/seek
Support seek write file
2 parents cf1b34c + 047bb9c commit 57e5a9b

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/sdk/bfs.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class File {
5454
File() {}
5555
virtual ~File() {}
5656
virtual int32_t Pread(char* buf, int32_t read_size, int64_t offset, bool reada = false) = 0;
57+
//for files opened with O_WRONLY, only support Seek(0, SEEK_CUR)
5758
virtual int64_t Seek(int64_t offset, int32_t whence) = 0;
5859
virtual int32_t Read(char* buf, int32_t read_size) = 0;
5960
virtual int32_t Write(const char* buf, int32_t write_size) = 0;

src/sdk/file_impl.cc

+3
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ int32_t FileImpl::Pread(char* buf, int32_t read_len, int64_t offset, bool reada)
270270
int64_t FileImpl::Seek(int64_t offset, int32_t whence) {
271271
//printf("Seek[%s:%d:%ld]\n", _name.c_str(), whence, offset);
272272
if (open_flags_ != O_RDONLY) {
273+
if (offset == 0 && whence == SEEK_CUR) {
274+
return common::atomic_add64(&write_offset_, 0);
275+
}
273276
return BAD_PARAMETER;
274277
}
275278
MutexLock lock(&read_offset_mu_);

0 commit comments

Comments
 (0)