Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lseek: Pass resulting offset via a pointer #482

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,13 +1113,13 @@ int posix_unlink(const char *pathname)
}


off_t posix_lseek(int fildes, off_t offset, int whence)
int posix_lseek(int fildes, off_t *offset, int whence)
{
TRACE("seek(%d, %d, %d)", fildes, offset, whence);

open_file_t *f;
off_t scnt;
int err;
int err = 0;

err = posix_getOpenFile(fildes, &f);
if (err != 0) {
Expand All @@ -1136,29 +1136,36 @@ off_t posix_lseek(int fildes, off_t offset, int whence)
proc_lockSet(&f->lock);
switch (whence) {
case SEEK_SET:
f->offset = offset;
scnt = f->offset;
scnt = *offset;
break;

case SEEK_CUR:
f->offset += offset;
scnt = f->offset;
scnt = f->offset + *offset;
break;

case SEEK_END:
scnt += offset;
f->offset = scnt;
scnt += *offset;
break;

default:
scnt = -EINVAL;
scnt = -1;
break;
}

if (scnt >= 0) {
f->offset = scnt;
}
else {
err = -EINVAL;
}

proc_lockClear(&f->lock);

posix_fileDeref(f);

return scnt;
*offset = scnt;

return err;
}


Expand Down
2 changes: 1 addition & 1 deletion posix/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern int posix_link(const char *path1, const char *path2);
extern int posix_unlink(const char *pathname);


extern off_t posix_lseek(int fildes, off_t offset, int whence);
extern int posix_lseek(int fildes, off_t *offset, int whence);


extern int posix_ftruncate(int fildes, off_t length);
Expand Down
11 changes: 8 additions & 3 deletions syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,16 +1068,21 @@ int syscalls_sys_unlink(char *ustack)
}


off_t syscalls_sys_lseek(char *ustack)
int syscalls_sys_lseek(char *ustack)
{
int fildes;
off_t offset;
off_t *offset;
int whence;

GETFROMSTACK(ustack, int, fildes, 0);
GETFROMSTACK(ustack, off_t, offset, 1);
GETFROMSTACK(ustack, off_t *, offset, 1);
GETFROMSTACK(ustack, int, whence, 2);

/* TODO verify pointer */
if (offset == NULL) {
return -EINVAL;
}

return posix_lseek(fildes, offset, whence);
}

Expand Down
Loading