diff --git a/tasks/libposix/lseek.c b/tasks/libposix/lseek.c index 683c096..7df100f 100644 --- a/tasks/libposix/lseek.c +++ b/tasks/libposix/lseek.c @@ -20,15 +20,14 @@ static inline off_t l4_lseek(int fildes, off_t offset, int whence) write_mr(L4SYS_ARG2, whence); /* Call pager with shmget() request. Check ipc error. */ - if ((errno = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_LSEEK)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, errno); - return -1; + if ((offres = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_LSEEK)) < 0) { + printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, offres); + return offres; } /* Check if syscall itself was successful */ if ((offres = l4_get_retval()) < 0) { printf("%s: OPEN Error: %d.\n", __FUNCTION__, (int)offres); - errno = (int)offres; - return -1; + return offres; } return offres; @@ -36,6 +35,15 @@ static inline off_t l4_lseek(int fildes, off_t offset, int whence) off_t lseek(int fildes, off_t offset, int whence) { - return l4_lseek(fildes, offset, whence); + int ret = l4_lseek(fildes, offset, whence); + + /* If error, return positive error code */ + if (ret < 0) { + errno = -ret; + return -1; + } + /* else return value */ + return ret; + } diff --git a/tasks/libposix/mmap.c b/tasks/libposix/mmap.c index 6eb99f5..dd5078d 100644 --- a/tasks/libposix/mmap.c +++ b/tasks/libposix/mmap.c @@ -12,6 +12,11 @@ #include #include +/* FIXME: Implement the same separation that is in read.c write.c etc. such that + * l4_syscall returns negative value and then the actual posix glue sets the errno + * rather than the l4_syscall sets it itself + */ + struct mmap_descriptor { void *start; size_t length; diff --git a/tasks/libposix/open.c b/tasks/libposix/open.c index a53569f..cb57247 100644 --- a/tasks/libposix/open.c +++ b/tasks/libposix/open.c @@ -23,22 +23,21 @@ static inline int l4_open(const char *pathname, int flags, mode_t mode) write_mr(L4SYS_ARG2, (u32)mode); /* Call pager with shmget() request. Check ipc error. */ - if ((errno = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_OPEN)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, errno); - return -1; + if ((fd = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_OPEN)) < 0) { + printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); + return fd; } /* Check if syscall itself was successful */ if ((fd = l4_get_retval()) < 0) { printf("%s: OPEN Error: %d.\n", __FUNCTION__, fd); - errno = fd; - return -1; - + return fd; } return fd; } int open(const char *pathname, int oflag, ...) { + int ret; mode_t mode = 0; if (oflag & O_CREAT) { @@ -47,6 +46,15 @@ int open(const char *pathname, int oflag, ...) mode = va_arg(arg, mode_t); va_end(arg); } - return l4_open(pathname, oflag, mode); + ret = l4_open(pathname, oflag, mode); + + /* If error, return positive error code */ + if (ret < 0) { + errno = -ret; + return -1; + } + /* else return value */ + return ret; + } diff --git a/tasks/libposix/write.c b/tasks/libposix/write.c index a0d25af..b64b31c 100644 --- a/tasks/libposix/write.c +++ b/tasks/libposix/write.c @@ -20,15 +20,14 @@ static inline int l4_write(int fd, const void *buf, size_t count) write_mr(L4SYS_ARG2, count); /* Call pager with shmget() request. Check ipc error. */ - if ((errno = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_WRITE)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, errno); - return -1; + if ((wrcnt = l4_sendrecv(VFS_TID, VFS_TID, L4_IPC_TAG_WRITE)) < 0) { + printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, wrcnt); + return wrcnt; } /* Check if syscall itself was successful */ if ((wrcnt = l4_get_retval()) < 0) { printf("%s: WRITE Error: %d.\n", __FUNCTION__, (int)wrcnt); - errno = (int)wrcnt; - return -1; + return wrcnt; } return wrcnt; @@ -36,9 +35,19 @@ static inline int l4_write(int fd, const void *buf, size_t count) ssize_t write(int fd, const void *buf, size_t count) { + int ret; + if (!count) return 0; - return l4_write(fd, buf, count); + ret = l4_write(fd, buf, count); + + /* If error, return positive error code */ + if (ret < 0) { + errno = -ret; + return -1; + } + /* else return value */ + return ret; }