From c675e57a22a0224f5cc5143390d6239f4b578538 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 7 Dec 2012 13:37:28 +0800 Subject: [PATCH] Usermode/libposix - Added stat(2) [stubbed] --- Usermode/Libraries/libposix.so_src/Makefile | 2 +- .../libposix.so_src/include_exp/sys/stat.h | 8 +-- Usermode/Libraries/libposix.so_src/stat.c | 53 +++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 Usermode/Libraries/libposix.so_src/stat.c diff --git a/Usermode/Libraries/libposix.so_src/Makefile b/Usermode/Libraries/libposix.so_src/Makefile index 73a0622f..737e4d6d 100644 --- a/Usermode/Libraries/libposix.so_src/Makefile +++ b/Usermode/Libraries/libposix.so_src/Makefile @@ -8,7 +8,7 @@ CFLAGS += -Werror -Wextra ASFLAGS += LDFLAGS += -soname libposix.so -Map map.txt -OBJ = main.o unistd.o dirent.o +OBJ = main.o unistd.o dirent.o stat.o DEPFILES := $(OBJ:%.o=%.d) BIN = libposix.so diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h index 99c526b2..3e9f4303 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h @@ -1,12 +1,13 @@ /* - * Acess2 C Library + * Acess2 POSIX Emulation Lib * - By John Hodge (thePowersGang) + * + * sys/stat.h + * - stat(2) */ #ifndef _SYS_STAT_H_ #define _SYS_STAT_H_ -//#include "../acess/intdefs.h" /* Evil */ -//#include "../stddef.h" #include #include "sys/types.h" // off_t @@ -48,6 +49,7 @@ struct stat }; extern int stat(const char *path, struct stat *buf); +extern int lstat(const char *path, struct stat *buf); extern int fstat(int fd, struct stat *buf); #endif diff --git a/Usermode/Libraries/libposix.so_src/stat.c b/Usermode/Libraries/libposix.so_src/stat.c new file mode 100644 index 00000000..198f7d5b --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/stat.c @@ -0,0 +1,53 @@ +/* + * Acess2 POSIX Emulation Lib + * - By John Hodge (thePowersGang) + * + * sys/stat.h + * - stat(2) + */ +#include +#include + +// === CODE === +int stat(const char *path, struct stat *buf) +{ + int fd = _SysOpen(path, 0); + if( !fd ) { + // errno is set by _SysOpen + return -1; + } + + int rv = fstat(fd, buf); + _SysClose(fd); + return rv; +} + +int lstat(const char *path, struct stat *buf) +{ + int fd = _SysOpen(path, OPENFLAG_NOLINK); + if( !fd ) { + // errno is set by _SysOpen + return -1; + } + + int rv = fstat(fd, buf); + _SysClose(fd); + return rv; +} + +int fstat(int fd, struct stat *buf) +{ + t_sysFInfo info; + + int rv = _SysFInfo(fd, &info, 0); + if( !rv ) { + return -1; + } + + // TODO: Populate buf + buf->st_mode = 0; +// memset(buf, 0, sizeof(*buf)); + + return 0; +} + -- 2.20.1