Browse Source

More libc stuff

K. Lange 4 years ago
parent
commit
554e6d10ed
4 changed files with 31 additions and 0 deletions
  1. 1 0
      base/usr/include/fcntl.h
  2. 15 0
      libc/unistd/chmod.c
  3. 8 0
      libc/unistd/setuid.c
  4. 7 0
      libc/unistd/sleep.c

+ 1 - 0
base/usr/include/fcntl.h

@@ -16,3 +16,4 @@
 #define X_OK 1
 
 extern int open (const char *, int, ...);
+extern int chmod(const char *path, mode_t mode);

+ 15 - 0
libc/unistd/chmod.c

@@ -0,0 +1,15 @@
+#include <errno.h>
+#include <syscall.h>
+#include <sys/stat.h>
+
+DEFN_SYSCALL2(chmod, 50, char *, int);
+
+int chmod(const char *path, mode_t mode) {
+	int result = syscall_chmod((char *)path, mode);
+	if (result < 0) {
+		errno = -result;
+		result = -1;
+	}
+	return result;
+}
+

+ 8 - 0
libc/unistd/setuid.c

@@ -0,0 +1,8 @@
+#include <syscall.h>
+#include <sys/types.h>
+
+DEFN_SYSCALL1(setuid, 24, unsigned int);
+
+int setuid(uid_t uid) {
+	return syscall_setuid(uid);
+}

+ 7 - 0
libc/unistd/sleep.c

@@ -0,0 +1,7 @@
+#include <syscall.h>
+
+unsigned int sleep(unsigned int seconds) {
+	syscall_nanosleep(seconds, 0);
+	return 0;
+}
+