From: John Hodge Date: Wed, 15 May 2013 08:11:34 +0000 (+0800) Subject: Usermode/libposix - fcntl and debug X-Git-Tag: rel0.15~479^2~1 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=015e01ffd34335e7232c4b6e039f18f39358f74c;p=tpg%2Facess2.git Usermode/libposix - fcntl and debug --- diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h index d45ffb64..bcd3d1fa 100644 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h @@ -25,6 +25,7 @@ #define OPENFLAG_APPEND 0x20 #define OPENFLAG_NOLINK 0x40 #define OPENFLAG_CREATE 0x80 +#define OPENFLAG_NONBLOCK 0x100 // How would this work? #ifndef SEEK_CUR # define SEEK_SET 1 # define SEEK_CUR 0 diff --git a/Usermode/Libraries/libposix.so_src/Makefile b/Usermode/Libraries/libposix.so_src/Makefile index 20b5fec4..6e666e8c 100644 --- a/Usermode/Libraries/libposix.so_src/Makefile +++ b/Usermode/Libraries/libposix.so_src/Makefile @@ -10,6 +10,7 @@ LDFLAGS += -soname libposix.so -Map map.txt -lc OBJ = main.o unistd.o dirent.o stat.o utmpx.o termios.o OBJ += pwd.o syslog.o sys_time.o sys_ioctl.o sys_resource.o +OBJ += fcntl.o DEPFILES := $(OBJ:%.o=%.d) BIN = libposix.so diff --git a/Usermode/Libraries/libposix.so_src/fcntl.c b/Usermode/Libraries/libposix.so_src/fcntl.c new file mode 100644 index 00000000..d57bca50 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/fcntl.c @@ -0,0 +1,59 @@ +/* + * Acess2 POSIX Emulation Library + * - By John Hodge (thePowersGang) + * + * fcntl.c + * - File descriptor control + */ +#include // off_t +#include +#include +#include +#include +#include + +// === CODE === +int fcntl(int fd, int cmd, ...) +{ + int ret; + va_list args; + va_start(args, cmd); + + switch(cmd) + { + case F_GETFL: { + int a_flags = _SysFDFlags(fd, 0, 0); + if( a_flags == -1 ) + return -1; + ret = 0; + if(a_flags & OPENFLAG_READ) ret |= O_RDONLY; + if(a_flags & OPENFLAG_WRITE) ret |= O_WRONLY; + if(a_flags & OPENFLAG_NONBLOCK) ret |= O_NONBLOCK; + if(a_flags & OPENFLAG_APPEND) ret |= O_APPEND; + // TODO: Extra flags for F_GETFL + break; } + case F_SETFL: { + long p_flags = va_arg(args, long); + int a_flags = 0; + const int mask = OPENFLAG_NONBLOCK|OPENFLAG_APPEND; + + if(p_flags & O_NONBLOCK) + a_flags |= OPENFLAG_NONBLOCK; + if(p_flags & O_APPEND) + a_flags |= OPENFLAG_APPEND; + // TODO: Extra flags for F_SETFL + + ret = _SysFDFlags(fd, mask, a_flags); + if(ret != -1) + ret = 0; + + break; } + default: + _SysDebug("fcntl(%i) unknown or unimplimented", cmd); + errno = EINVAL; + ret = -1; + break; + } + va_end(args); + return ret; +} diff --git a/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h b/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h index bdb54226..f53ad935 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/fcntl.h @@ -1,9 +1,9 @@ /* - * Acess2 C Library (UNIX Emulation) + * Acess2 POSIX Emulation Library * - By John Hodge (thePowersGang) * * fcntl.h - * - ?? + * - File descriptor control? */ #ifndef _FCNTL_H_ @@ -32,7 +32,7 @@ enum e_fcntl_cmds F_GETLK, // (struct flock *) }; -static inline int fcntl(int fd __attribute__((unused)), int cmd __attribute__((unused)), ...) { return -1; } +extern int fcntl(int fd, int cmd, ...); #endif diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c index 57d71258..5f974404 100644 --- a/Usermode/Libraries/libposix.so_src/unistd.c +++ b/Usermode/Libraries/libposix.so_src/unistd.c @@ -89,6 +89,7 @@ int execv(const char *b, char *v[]) int dup(int oldfd) { + _SysDebug("libposix: dup() does not share offsets/flags"); // NOTE: Acess's CopyFD doesn't cause offset sharing // TODO: Check that -1 does cause a new allocation return _SysCopyFD(oldfd, -1); @@ -96,6 +97,7 @@ int dup(int oldfd) int dup2(int oldfd, int newfd) { + _SysDebug("libposix: dup2() does not share offsets/flags"); // NOTE: Acess's CopyFD doesn't cause offset sharing return _SysCopyFD(oldfd, newfd); }