Skip to content

Commit

Permalink
Merge pull request #511 from yvxiang/seek
Browse files Browse the repository at this point in the history
Support seek write file
  • Loading branch information
lylei committed Oct 10, 2016
2 parents cf1b34c + 047bb9c commit 57e5a9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/sdk/bfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class File {
File() {}
virtual ~File() {}
virtual int32_t Pread(char* buf, int32_t read_size, int64_t offset, bool reada = false) = 0;
//for files opened with O_WRONLY, only support Seek(0, SEEK_CUR)
virtual int64_t Seek(int64_t offset, int32_t whence) = 0;
virtual int32_t Read(char* buf, int32_t read_size) = 0;
virtual int32_t Write(const char* buf, int32_t write_size) = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/sdk/file_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ int32_t FileImpl::Pread(char* buf, int32_t read_len, int64_t offset, bool reada)
int64_t FileImpl::Seek(int64_t offset, int32_t whence) {
//printf("Seek[%s:%d:%ld]\n", _name.c_str(), whence, offset);
if (open_flags_ != O_RDONLY) {
if (offset == 0 && whence == SEEK_CUR) {
return common::atomic_add64(&write_offset_, 0);
}
return BAD_PARAMETER;
}
MutexLock lock(&read_offset_mu_);
Expand Down

0 comments on commit 57e5a9b

Please sign in to comment.