summaryrefslogtreecommitdiff
path: root/LibC
diff options
context:
space:
mode:
Diffstat (limited to 'LibC')
-rw-r--r--LibC/errno_numbers.h48
-rw-r--r--LibC/signal.cpp14
-rw-r--r--LibC/signal.h24
-rw-r--r--LibC/signal_numbers.h44
-rw-r--r--LibC/stat.cpp12
-rw-r--r--LibC/string.cpp18
-rw-r--r--LibC/string.h1
-rw-r--r--LibC/unistd.h6
8 files changed, 133 insertions, 34 deletions
diff --git a/LibC/errno_numbers.h b/LibC/errno_numbers.h
new file mode 100644
index 0000000000..89a9e582c2
--- /dev/null
+++ b/LibC/errno_numbers.h
@@ -0,0 +1,48 @@
+#pragma once
+
+#define __ENUMERATE_ALL_ERRORS \
+ __ERROR(EPERM, "Operation not permitted") \
+ __ERROR(ENOENT, "No such file or directory") \
+ __ERROR(ESRCH, "No such process") \
+ __ERROR(EINTR, "Interrupted syscall") \
+ __ERROR(EIO, "I/O error") \
+ __ERROR(ENXIO, "No such device or address") \
+ __ERROR(E2BIG, "Argument list too long") \
+ __ERROR(ENOEXEC, "Exec format error") \
+ __ERROR(EBADF, "Bad fd number") \
+ __ERROR(ECHILD, "No child processes") \
+ __ERROR(EAGAIN, "Try again") \
+ __ERROR(ENOMEM, "Out of memory") \
+ __ERROR(EACCES, "Permission denied") \
+ __ERROR(EFAULT, "Bad address") \
+ __ERROR(ENOTBLK, "Block device required") \
+ __ERROR(EBUSY, "Device or resource busy") \
+ __ERROR(EEXIST, "File already exists") \
+ __ERROR(EXDEV, "Cross-device link") \
+ __ERROR(ENODEV, "No such device") \
+ __ERROR(ENOTDIR, "Not a directory") \
+ __ERROR(EISDIR, "Is a directory") \
+ __ERROR(EINVAL, "Invalid argument") \
+ __ERROR(ENFILE, "File table overflow") \
+ __ERROR(EMFILE, "Too many open files") \
+ __ERROR(ENOTTY, "Not a TTY") \
+ __ERROR(ETXTBSY, "Text file busy") \
+ __ERROR(EFBIG, "File too large") \
+ __ERROR(ENOSPC, "No space left on device") \
+ __ERROR(ESPIPE, "Illegal seek") \
+ __ERROR(EROFS, "Read-only filesystem") \
+ __ERROR(EMLINK, "Too many links") \
+ __ERROR(EPIPE, "Broken pipe") \
+ __ERROR(ERANGE, "Range error") \
+ __ERROR(ENAMETOOLONG, "Name too long") \
+ __ERROR(ELOOP, "Too many symlinks") \
+ __ERROR(EOVERFLOW, "Overflow") \
+ __ERROR(ENOTIMPL, "Not implemented") \
+
+enum __errno_values {
+#undef __ERROR
+#define __ERROR(a, b) a,
+ __ENUMERATE_ALL_ERRORS
+#undef __ERROR
+ __errno_count
+};
diff --git a/LibC/signal.cpp b/LibC/signal.cpp
index c42802df12..b348128308 100644
--- a/LibC/signal.cpp
+++ b/LibC/signal.cpp
@@ -46,7 +46,7 @@ int sigaddset(sigset_t* set, int sig)
errno = EINVAL;
return -1;
}
- *set |= 1 << (sig - 1);
+ *set |= 1 << (sig);
return 0;
}
@@ -56,7 +56,7 @@ int sigdelset(sigset_t* set, int sig)
errno = EINVAL;
return -1;
}
- *set &= ~(1 << (sig - 1));
+ *set &= ~(1 << (sig));
return 0;
}
@@ -66,9 +66,17 @@ int sigismember(const sigset_t* set, int sig)
errno = EINVAL;
return -1;
}
- if (*set & (1 << (sig - 1)))
+ if (*set & (1 << (sig)))
return 1;
return 0;
}
+const char* sys_siglist[NSIG] = {
+#undef __SIGNAL
+#define __SIGNAL(a, b) b,
+ __ENUMERATE_ALL_SIGNALS
+#undef __SIGNAL
+};
+
+
}
diff --git a/LibC/signal.h b/LibC/signal.h
index 03e2f03d4a..0cc5e5a142 100644
--- a/LibC/signal.h
+++ b/LibC/signal.h
@@ -1,6 +1,7 @@
#pragma once
#include <sys/types.h>
+#include <signal_numbers.h>
__BEGIN_DECLS
@@ -29,6 +30,9 @@ int sigaddset(sigset_t*, int sig);
int sigdelset(sigset_t*, int sig);
int sigismember(const sigset_t*, int sig);
+#define NSIG 32
+extern const char* sys_siglist[NSIG];
+
#define SIG_DFL ((__sighandler_t)0)
#define SIG_ERR ((__sighandler_t)-1)
#define SIG_IGN ((__sighandler_t)1)
@@ -41,25 +45,5 @@ int sigismember(const sigset_t*, int sig);
#define SIG_UNBLOCK 1
#define SIG_SETMASK 2
-#define SIGHUP 1
-#define SIGINT 2
-#define SIGQUIT 3
-#define SIGILL 4
-#define SIGTRAP 5
-#define SIGABRT 6
-#define SIGBUS 7
-#define SIGFPE 8
-#define SIGKILL 9
-#define SIGUSR1 10
-#define SIGSEGV 11
-#define SIGUSR2 12
-#define SIGPIPE 13
-#define SIGALRM 14
-#define SIGTERM 15
-#define SIGCONT 18
-#define SIGTSTP 20
-#define SIGTTIN 21
-#define SIGTTOU 22
-
__END_DECLS
diff --git a/LibC/signal_numbers.h b/LibC/signal_numbers.h
new file mode 100644
index 0000000000..a26beeaa15
--- /dev/null
+++ b/LibC/signal_numbers.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#define __ENUMERATE_ALL_SIGNALS \
+ __SIGNAL(SIGINVAL, "Invalid signal number") \
+ __SIGNAL(SIGHUP, "Hangup") \
+ __SIGNAL(SIGINT, "Interrupt") \
+ __SIGNAL(SIGQUIT, "Quit") \
+ __SIGNAL(SIGILL, "Illegal instruction") \
+ __SIGNAL(SIGTRAP, "Trap") \
+ __SIGNAL(SIGABRT, "Aborted") \
+ __SIGNAL(SIGBUS, "Bus error") \
+ __SIGNAL(SIGFPE, "FP exception") \
+ __SIGNAL(SIGKILL, "Killed") \
+ __SIGNAL(SIGUSR1, "User signal 1") \
+ __SIGNAL(SIGSEGV, "Segmentation violation") \
+ __SIGNAL(SIGUSR2, "User signal 2") \
+ __SIGNAL(SIGPIPE, "Broken pipe") \
+ __SIGNAL(SIGALRM, "Alarm clock") \
+ __SIGNAL(SIGTERM, "Terminated") \
+ __SIGNAL(SIGSTKFLT, "Stack fault") \
+ __SIGNAL(SIGCHLD, "Child exited") \
+ __SIGNAL(SIGCONT, "Continued") \
+ __SIGNAL(SIGSTOP, "Stopped (signal)") \
+ __SIGNAL(SIGTSTP, "Stopped") \
+ __SIGNAL(SIGTTIN, "Stopped (tty input)") \
+ __SIGNAL(SIGTTOU, "Stopped (tty output)") \
+ __SIGNAL(SIGURG, "Urgent I/O condition)") \
+ __SIGNAL(SIGXCPU, "CPU limit exceeded") \
+ __SIGNAL(SIGXFSZ, "File size limit exceeded") \
+ __SIGNAL(SIGVTALRM, "Virtual timer expired") \
+ __SIGNAL(SIGPROF, "Profiling timer expired") \
+ __SIGNAL(SIGWINCH, "Window changed") \
+ __SIGNAL(SIGIO, "I/O possible") \
+ __SIGNAL(SIGPWR, "Power failure") \
+ __SIGNAL(SIGSYS, "Bad system call") \
+
+
+enum __signal_numbers {
+#undef __SIGNAL
+#define __SIGNAL(a, b) a,
+ __ENUMERATE_ALL_SIGNALS
+#undef __SIGNAL
+ __signal_count
+};
diff --git a/LibC/stat.cpp b/LibC/stat.cpp
new file mode 100644
index 0000000000..9dd53da298
--- /dev/null
+++ b/LibC/stat.cpp
@@ -0,0 +1,12 @@
+#include <sys/stat.h>
+#include <Kernel/Syscall.h>
+
+extern "C" {
+
+mode_t umask(mode_t mask)
+{
+ return Syscall::invoke(Syscall::SC_umask, (dword)mask);
+}
+
+}
+
diff --git a/LibC/string.cpp b/LibC/string.cpp
index 3f5fafb1bc..e905248ed0 100644
--- a/LibC/string.cpp
+++ b/LibC/string.cpp
@@ -1,6 +1,7 @@
-#include "string.h"
-#include "errno.h"
-#include "stdio.h"
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <signal.h>
extern "C" {
@@ -157,7 +158,7 @@ char* strncat(char *dest, const char *src, size_t n)
const char* sys_errlist[] = {
#undef __ERROR
-#define __ERROR(a, b) #b,
+#define __ERROR(a, b) b,
__ENUMERATE_ALL_ERRORS
#undef __ERROR
};
@@ -170,8 +171,15 @@ char* strerror(int errnum)
return "Unknown error";
}
return (char*)sys_errlist[errnum];
-
}
+char* strsignal(int signum)
+{
+ if (signum >= __signal_count) {
+ printf("strsignal() missing string for signum=%d\n", signum);
+ return "Unknown signal";
+ }
+ return (char*)sys_siglist[signum];
}
+}
diff --git a/LibC/string.h b/LibC/string.h
index 2693ae19b5..cb0c9ddd9b 100644
--- a/LibC/string.h
+++ b/LibC/string.h
@@ -23,6 +23,7 @@ char* strncat(char *dest, const char *src, size_t);
size_t strspn(const char*, const char* accept);
size_t strcspn(const char*, const char* reject);
char* strerror(int errnum);
+char* strsignal(int signum);
__END_DECLS
diff --git a/LibC/unistd.h b/LibC/unistd.h
index 9b388e0733..69d9e9c31c 100644
--- a/LibC/unistd.h
+++ b/LibC/unistd.h
@@ -48,12 +48,6 @@ int dup2(int old_fd, int new_fd);
#define WIFEXITED(status) (WTERMSIG(status) == 0)
#define WIFSIGNALED(status) (((char) (((status) & 0x7f) + 1) >> 1) > 0)
-#define SIGINT 2
-#define SIGKILL 9
-#define SIGSEGV 11
-#define SIGTERM 15
-#define SIGCHLD 17
-
#define HOST_NAME_MAX 64
#define S_IFMT 0170000