feat(iso): add seek function
This commit is contained in:
parent
525739572f
commit
90a6ebafe9
25
k/iso.c
25
k/iso.c
@ -102,6 +102,31 @@ s64 read(int fd, void *buf, size_t count)
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s64 seek(int fd, u32 offset, int whence)
|
||||||
|
{
|
||||||
|
if (fd > MAX_FD)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
struct file_entry *f = &fd_table[fd];
|
||||||
|
if (!f->open)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
switch (whence)
|
||||||
|
{
|
||||||
|
case SEEK_SET:
|
||||||
|
f->file_offset = offset;
|
||||||
|
break;
|
||||||
|
case SEEK_CUR:
|
||||||
|
f->file_offset += offset;
|
||||||
|
break;
|
||||||
|
case SEEK_END:
|
||||||
|
f->file_offset = f->file_size + offset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return f->file_offset;
|
||||||
|
}
|
||||||
|
|
||||||
int close(int fd)
|
int close(int fd)
|
||||||
{
|
{
|
||||||
return destroy_fd(fd);
|
return destroy_fd(fd);
|
||||||
|
8
k/iso.h
8
k/iso.h
@ -3,10 +3,18 @@
|
|||||||
|
|
||||||
#include <k/types.h>
|
#include <k/types.h>
|
||||||
|
|
||||||
|
/* open flags */
|
||||||
#define O_RDONLY 0
|
#define O_RDONLY 0
|
||||||
|
|
||||||
|
/* seek flags */
|
||||||
|
#define SEEK_SET 0
|
||||||
|
#define SEEK_CUR 1
|
||||||
|
#define SEEK_END 2
|
||||||
|
|
||||||
|
/* functions */
|
||||||
int open(const char *path, int flags);
|
int open(const char *path, int flags);
|
||||||
s64 read(int fd, void *buf, size_t count);
|
s64 read(int fd, void *buf, size_t count);
|
||||||
|
s64 seek(int fd, u32 offset, int whence);
|
||||||
int close(int fd);
|
int close(int fd);
|
||||||
|
|
||||||
#endif /* !ISO_H */
|
#endif /* !ISO_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user