BarryServer : Git

All the code for all my projects
// BarryServer : Git / OrionLibC / commit / 03048a95d88cc7a78171393371f5c22a0250a014 / unistd / open.c

// Related

OrionLibC

Barry Importing existing Orion LibC 03048a9 (2 years, 2 months ago)
diff --git a/unistd/open.c b/unistd/open.c
new file mode 100644
index 0000000..02603d8
--- /dev/null
+++ b/unistd/open.c
@@ -0,0 +1,30 @@
+#include <fcntl.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <errno.h>
+
+/* Open a file */
+int
+open(const char *name, int flags, ...)
+{
+	int ret;
+	if (flags & O_CREATE) {
+		asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_OPEN),
+		             "c" (3), "S" (&name));
+	} else {
+		asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_OPEN),
+		             "c" (2), "S" (&name));
+	}
+
+	if (ret >= 0)
+		return ret;
+	errno = -ret;
+	return -1;
+}
+
+/* Create a file */
+int
+create(const char *name, mode_t mode)
+{
+	return open(name, O_CREATE | O_WRONLY | O_TRUNC, mode);
+}