From 7f04b67582bbb3d65a4ce5516d3e12cccee62ef3 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 6 Jan 2022 11:37:23 +0000 Subject: [PATCH] Implemented open() and openat() on Horizon --- photon/libc/sys/horizon/unistd.c | 36 +++++++++++++++++++++----------- photon/libc/sys/horizon/unistd.h | 4 +++- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/photon/libc/sys/horizon/unistd.c b/photon/libc/sys/horizon/unistd.c index 96afd1b..3382f75 100644 --- a/photon/libc/sys/horizon/unistd.c +++ b/photon/libc/sys/horizon/unistd.c @@ -2,6 +2,30 @@ #include #include +int open(const char *pathname, int flags, ...) +{ + int ret = mio_open(pathname, flags); + if (ret < 0) { + __set_errno(-ret); + return -1; + } + + __set_errno(0); + return ret; +} + +int openat(int dirfd, const char *pathname, int flags, ...) +{ + int ret = mio_openat(dirfd, pathname, flags); + if (ret < 0) { + __set_errno(-ret); + return -1; + } + + __set_errno(0); + return ret; +} + ssize_t read(int fd, void *buf, size_t count) { ssize_t ret = mio_read(fd, buf, count); @@ -26,18 +50,6 @@ ssize_t write(int fd, const void *buf, size_t count) return ret; } -int open(const char *pathname, int flags) -{ - int ret = mio_open(pathname, flags); - if (ret < 0) { - __set_errno(-ret); - return -1; - } - - __set_errno(0); - return ret; -} - int close(int fd) { int ret = mio_close(fd); diff --git a/photon/libc/sys/horizon/unistd.h b/photon/libc/sys/horizon/unistd.h index 76fcc64..11b83de 100644 --- a/photon/libc/sys/horizon/unistd.h +++ b/photon/libc/sys/horizon/unistd.h @@ -9,9 +9,11 @@ struct stat; struct pollfd; +extern int open(const char *pathname, int flags, ...); +extern int openat(int dirfd, const char *pathname, int flags, ...); + extern ssize_t read(int fd, void *buf, size_t count); extern ssize_t write(int fd, const void *buf, size_t count); -extern int open(const char *pathname, int flags); extern int close(int fd); #endif