From e226d50f04e1226078858a15dd03aa81d03f7e2c Mon Sep 17 00:00:00 2001
From: whh8b <whh8b@git.zephyr-software.com>
Date: Mon, 11 Apr 2016 03:31:17 +0000
Subject: [PATCH] Add support for open modes and for mkfifo.

---
 libc/include/open.h    | 65 +++++++++++++++++++++++++++++++++++++++++-
 libc/include/stdlib.h  |  6 ++++
 libc/include/syscall.h |  1 +
 libc/src/Makefile.in   |  2 +-
 libc/src/open.c        | 13 +++++++--
 5 files changed, 82 insertions(+), 5 deletions(-)

diff --git a/libc/include/open.h b/libc/include/open.h
index 459dfb4..72d53d6 100644
--- a/libc/include/open.h
+++ b/libc/include/open.h
@@ -23,7 +23,70 @@
 
 #include <stdint.h>
 
-int open(char *file, int mode);
+/* open/fcntl.  */
+#define O_ACCMODE	   0003
+#define O_RDONLY	     00
+#define O_WRONLY	     01
+#define O_RDWR		     02
+#ifndef O_CREAT
+# define O_CREAT	   0100	/* Not fcntl.  */
+#endif
+#ifndef O_EXCL
+# define O_EXCL		   0200	/* Not fcntl.  */
+#endif
+#ifndef O_NOCTTY
+# define O_NOCTTY	   0400	/* Not fcntl.  */
+#endif
+#ifndef O_TRUNC
+# define O_TRUNC	  01000	/* Not fcntl.  */
+#endif
+#ifndef O_APPEND
+# define O_APPEND	  02000
+#endif
+#ifndef O_NONBLOCK
+# define O_NONBLOCK	  04000
+#endif
+#ifndef O_NDELAY
+# define O_NDELAY	O_NONBLOCK
+#endif
+#ifndef O_SYNC
+# define O_SYNC	       04010000
+#endif
+#define O_FSYNC		O_SYNC
+#ifndef O_ASYNC
+# define O_ASYNC	 020000
+#endif
+
+/* Protection bits.  */
+
+#define	__S_ISUID	04000	/* Set user ID on execution.  */
+#define	__S_ISGID	02000	/* Set group ID on execution.  */
+#define	__S_ISVTX	01000	/* Save swapped text after use (sticky).  */
+#define	__S_IREAD	0400	/* Read by owner.  */
+#define	__S_IWRITE	0200	/* Write by owner.  */
+#define	__S_IEXEC	0100	/* Execute by owner.  */
+
+
+# define S_IRUSR	__S_IREAD       /* Read by owner.  */
+# define S_IWUSR	__S_IWRITE      /* Write by owner.  */
+# define S_IXUSR	__S_IEXEC       /* Execute by owner.  */
+/* Read, write, and execute by owner.  */
+# define S_IRWXU	(__S_IREAD|__S_IWRITE|__S_IEXEC)
+
+# define S_IRGRP	(S_IRUSR >> 3)  /* Read by group.  */
+# define S_IWGRP	(S_IWUSR >> 3)  /* Write by group.  */
+# define S_IXGRP	(S_IXUSR >> 3)  /* Execute by group.  */
+/* Read, write, and execute by group.  */
+# define S_IRWXG	(S_IRWXU >> 3)
+
+# define S_IROTH	(S_IRGRP >> 3)  /* Read by others.  */
+# define S_IWOTH	(S_IWGRP >> 3)  /* Write by others.  */
+# define S_IXOTH	(S_IXGRP >> 3)  /* Execute by others.  */
+/* Read, write, and execute by others.  */
+# define S_IRWXO	(S_IRWXG >> 3)
+
+//int open(char *file, int flags, ...);
+int open(char *file, int flags, int mode);
 
 #endif
 
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 8b39fa1..82a3323 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -28,5 +28,11 @@
 void __stack_chk_fail(void);
 
 #include <malloc.h>
+#include <open.h>
+#include <close.h>
+#include <read.h>
+#include <write.h>
+#include <mkfifo.h>
+#include <syscall.h>
 
 #endif
diff --git a/libc/include/syscall.h b/libc/include/syscall.h
index 115c35d..6a467b1 100644
--- a/libc/include/syscall.h
+++ b/libc/include/syscall.h
@@ -23,6 +23,7 @@
 #define SYS_write 1
 #define SYS_open 2
 #define SYS_close 3
+#define SYS_mknod 133
 #else
 #define SYS_read 3
 #define SYS_write 4
diff --git a/libc/src/Makefile.in b/libc/src/Makefile.in
index 1560c20..f428d84 100644
--- a/libc/src/Makefile.in
+++ b/libc/src/Makefile.in
@@ -7,7 +7,7 @@ AR=@AR@
 AS=@AS@
 ASFLAGS=@ASFLAGS@
 
-OBJS=malloc.o read.o write.o itoa.o strlen.o cgc.o open.o close.o stdlib.o
+OBJS=malloc.o read.o write.o itoa.o strlen.o cgc.o open.o close.o stdlib.o mkfifo.o
 
 # note:  cgc.s is empty when -DCGC is not in ASFLAGS, so it's an empty object file that's created..
 
diff --git a/libc/src/open.c b/libc/src/open.c
index 21b943f..f5428d2 100644
--- a/libc/src/open.c
+++ b/libc/src/open.c
@@ -21,10 +21,17 @@
 #include <open.h>
 #include <syscall.h>
 
-int open(char *file, int mode)
+/*
+int open(char *file, int flags)
 {
 #ifndef CGC
-	syscall(SYS_open,file,mode);
+	syscall(SYS_open,file,flags);
+#endif
+}
+*/
+int open(char *file, int flags, int mode)
+{
+#ifndef CGC
+	syscall(SYS_open,file,flags,mode);
 #endif
 }
-
-- 
GitLab