--- /dev/null
+/*
+ * 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;
+}
/*
- * Acess2 C Library (UNIX Emulation)
+ * Acess2 POSIX Emulation Library
* - By John Hodge (thePowersGang)
*
* fcntl.h
- * - ??
+ * - File descriptor control?
*/
#ifndef _FCNTL_H_
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
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);
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);
}