2021-12-10 07:25:00 +01:00
|
|
|
#include <unistd.h>
|
2021-12-13 18:38:47 +01:00
|
|
|
#include <gint/fs.h>
|
|
|
|
#include <errno.h>
|
2021-12-10 07:25:00 +01:00
|
|
|
|
|
|
|
off_t lseek(int fd, off_t offset, int whence)
|
|
|
|
{
|
2021-12-21 19:01:00 +01:00
|
|
|
if(whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return (off_t)-1;
|
|
|
|
}
|
|
|
|
|
2021-12-13 18:38:47 +01:00
|
|
|
fs_descriptor_t const *d = fs_get_descriptor(fd);
|
|
|
|
if(!d) {
|
|
|
|
errno = EBADF;
|
|
|
|
return (ssize_t)-1;
|
2021-12-10 07:25:00 +01:00
|
|
|
}
|
|
|
|
|
2021-12-13 18:38:47 +01:00
|
|
|
if(d->type->lseek)
|
|
|
|
return d->type->lseek(d->data, offset, whence);
|
2021-12-10 07:25:00 +01:00
|
|
|
|
2021-12-13 18:38:47 +01:00
|
|
|
/* No seek function: cannot seek */
|
|
|
|
return 0;
|
2021-12-10 07:25:00 +01:00
|
|
|
}
|