AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
lseek.c
Go to the documentation of this file.
1
5
6#include <core/system.h>
7#include <fs/vfs.h>
8#include <fs/posix.h>
9#include <aquila/errno.h>
10
22off_t posix_file_lseek(struct file *file, off_t offset, int whence)
23{
24 struct vnode *vnode = file->vnode;
25 off_t new_offset;
26
27 switch (whence) {
28 case 0: /* SEEK_SET */
29 new_offset = offset;
30 break;
31 case 1: /* SEEK_CUR */
32 new_offset = file->offset + offset;
33 break;
34 case 2: /* SEEK_END */
35 new_offset = (off_t) vnode->size + offset;
36 break;
37 default:
38 return -EINVAL;
39 }
40
41 /* the new offset would be negative */
42 if (new_offset < 0)
43 return -EINVAL;
44
45 file->offset = new_offset;
46 return file->offset;
47}
off_t posix_file_lseek(struct file *file, off_t offset, int whence)
Moves an open file's offset: to offset (SEEK_SET), by offset from where it is (SEEK_CUR),...
Definition lseek.c:22
An open file (POSIX's "open file description", fs/file.c).
Definition vfs.h:157
off_t offset
Definition vfs.h:163
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113
size_t size
Definition vfs.h:115
long int off_t
Definition types.h:10