mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
Errno is set by the posix calls read/write/open/close etc. rather than their l4_xxx equivalent.
mmap.c is the only one not done yet.
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/ipcdefs.h>
|
||||
|
||||
/* 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user