Usermode/libposix - fcntl and debug
authorJohn Hodge <[email protected]>
Wed, 15 May 2013 08:11:34 +0000 (16:11 +0800)
committerJohn Hodge <[email protected]>
Wed, 15 May 2013 08:11:34 +0000 (16:11 +0800)
Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h
Usermode/Libraries/libposix.so_src/Makefile
Usermode/Libraries/libposix.so_src/fcntl.c [new file with mode: 0644]
Usermode/Libraries/libposix.so_src/include_exp/fcntl.h
Usermode/Libraries/libposix.so_src/unistd.c

index d45ffb6..bcd3d1f 100644 (file)
@@ -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
index 20b5fec..6e666e8 100644 (file)
@@ -10,6 +10,7 @@ LDFLAGS  += -soname libposix.so -Map map.txt -lc
 \r
 OBJ  = main.o unistd.o dirent.o stat.o utmpx.o termios.o\r
 OBJ += pwd.o syslog.o sys_time.o sys_ioctl.o sys_resource.o\r
+OBJ += fcntl.o\r
 DEPFILES := $(OBJ:%.o=%.d)\r
 BIN = libposix.so\r
 \r
diff --git a/Usermode/Libraries/libposix.so_src/fcntl.c b/Usermode/Libraries/libposix.so_src/fcntl.c
new file mode 100644 (file)
index 0000000..d57bca5
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Acess2 POSIX Emulation Library
+ * - By John Hodge (thePowersGang)
+ *
+ * fcntl.c
+ * - File descriptor control
+ */
+#include <sys/types.h> // off_t
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <acess/sys.h>
+#include <errno.h>
+
+// === 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;
+}
index bdb5422..f53ad93 100644 (file)
@@ -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
 
index 57d7125..5f97440 100644 (file)
@@ -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);
 }

UCC git Repository :: git.ucc.asn.au