lib: c: io: implement lseek()
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define UNISTD_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
extern int open(const char *path, int flags);
|
||||
extern int close(int fd);
|
||||
@@ -9,4 +10,6 @@ extern int close(int fd);
|
||||
extern int read(int fd, void *buf, size_t count);
|
||||
extern int write(int fd, const void *buf, size_t count);
|
||||
|
||||
extern off_t lseek(int fd, off_t offset, int whence);
|
||||
|
||||
#endif
|
||||
|
||||
22
lib/libc/io/unistd/lseek.c
Normal file
22
lib/libc/io/unistd/lseek.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/msg.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <sys/remote.h>
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
int err;
|
||||
off_t new_offset;
|
||||
|
||||
kern_status_t status = fs_seek(fd, offset, whence, &err, &new_offset);
|
||||
if (status != KERN_OK) {
|
||||
return __set_errno(__errno_from_kern_status(status));
|
||||
}
|
||||
|
||||
if (err != SUCCESS) {
|
||||
return __set_errno(err);
|
||||
}
|
||||
|
||||
return new_offset;
|
||||
}
|
||||
Reference in New Issue
Block a user