mufs: implement mufs_seek() to seek and tell the position within a file
This commit is contained in:
parent
9ef95baac3
commit
a20c1a8ed4
2 changed files with 21 additions and 0 deletions
|
@ -42,5 +42,6 @@ int mufs_mkdir(struct mufs *fs, const char *path);
|
|||
int mufs_create(struct mufs *fs, const char *path);
|
||||
struct mufs_file *mufs_open(struct mufs *fs, const char *path, int mode);
|
||||
void mufs_close(struct mufs_file *file);
|
||||
long mufs_seek(struct mufs_file *file, long offset, int whence);
|
||||
size_t mufs_read(struct mufs_file *file, void *data, size_t len);
|
||||
size_t mufs_write(struct mufs_file *file, const void *data, size_t len);
|
||||
|
|
|
@ -54,6 +54,26 @@ void mufs_close(struct mufs_file *file)
|
|||
free(file);
|
||||
}
|
||||
|
||||
long mufs_seek(struct mufs_file *file, long offset, int whence)
|
||||
{
|
||||
if (!file)
|
||||
return -1;
|
||||
|
||||
switch (whence) {
|
||||
case SEEK_SET: break;
|
||||
case SEEK_CUR: offset = file->va + offset; break;
|
||||
case SEEK_END: offset = file->tree->file_size; break;
|
||||
default: return -1;
|
||||
}
|
||||
|
||||
if (offset > file->tree->file_size || offset >= UINT32_MAX)
|
||||
return -1;
|
||||
|
||||
file->va = offset;
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
size_t mufs_read(struct mufs_file *file, void *data, size_t len)
|
||||
{
|
||||
size_t ret;
|
||||
|
|
Loading…
Add table
Reference in a new issue