diff --git a/LibC/dirent.cpp b/LibC/dirent.cpp index 9e4ee1c7fee..41fd6443fb8 100644 --- a/LibC/dirent.cpp +++ b/LibC/dirent.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include extern "C" { diff --git a/LibC/errno_numbers.h b/LibC/errno_numbers.h index 57a2bab42b5..87f09a748d0 100644 --- a/LibC/errno_numbers.h +++ b/LibC/errno_numbers.h @@ -40,6 +40,7 @@ __ERROR(EOPNOTSUPP, "Operation not supported") \ __ERROR(ENOSYS, "No such syscall") \ __ERROR(ENOTIMPL, "Not implemented") \ + __ERROR(EAFNOSUPPORT, "Address family not supported") \ enum __errno_values { #undef __ERROR diff --git a/LibC/fcntl.h b/LibC/fcntl.h index c717acdc1a2..5181ff22df9 100644 --- a/LibC/fcntl.h +++ b/LibC/fcntl.h @@ -12,6 +12,19 @@ __BEGIN_DECLS #define FD_CLOEXEC 1 +#define O_RDONLY 0 +#define O_WRONLY 1 +#define O_RDWR 2 +#define O_CREAT 0100 +#define O_EXCL 0200 +#define O_NOCTTY 0400 +#define O_TRUNC 01000 +#define O_APPEND 02000 +#define O_NONBLOCK 04000 +#define O_DIRECTORY 00200000 +#define O_NOFOLLOW 00400000 +#define O_CLOEXEC 02000000 + int fcntl(int fd, int cmd, ...); __END_DECLS diff --git a/LibC/limits.h b/LibC/limits.h index 295bef570ba..616e916b4ef 100644 --- a/LibC/limits.h +++ b/LibC/limits.h @@ -8,7 +8,18 @@ #define INT_MAX INT32_MAX #define INT_MIN INT32_MIN +#define UINT_MAX UINT32_MAX +#define UINT_MIN UINT32_MIN + #define CHAR_BIT 8 #define SCHAR_MIN (-128) #define SCHAR_MAX 127 #define UCHAR_MAX 255 + +#define LONG_MAX 2147483647L +#define LONG_MIN (-LONG_MAX - 1L) + +#define CHAR_MIN SCHAR_MIN +#define CHAR_MAX SCHAR_MAX + +#define MB_LEN_MAX 16 diff --git a/LibC/locale.h b/LibC/locale.h new file mode 100644 index 00000000000..d5e4530d09c --- /dev/null +++ b/LibC/locale.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +enum { + LC_ALL, + LC_NUMERIC, +}; + +__BEGIN_DECLS + +char* setlocale(int category, const char* locale); + +__END_DECLS + diff --git a/LibC/stdio.cpp b/LibC/stdio.cpp index d04373c7d20..ed49a3ee1f5 100644 --- a/LibC/stdio.cpp +++ b/LibC/stdio.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/LibC/stdlib.cpp b/LibC/stdlib.cpp index b28df2a161c..5a9ee58a579 100644 --- a/LibC/stdlib.cpp +++ b/LibC/stdlib.cpp @@ -66,8 +66,8 @@ void* realloc(void *ptr, size_t size) void exit(int status) { - Syscall::invoke(Syscall::SC_exit, (dword)status); - for (;;); + _exit(status); + assert(false); } void abort() diff --git a/LibC/stdlib.h b/LibC/stdlib.h index 243b98693fd..c88d0ff5976 100644 --- a/LibC/stdlib.h +++ b/LibC/stdlib.h @@ -5,6 +5,9 @@ __BEGIN_DECLS +#define EXIT_SUCCESS 0 +#define EXIT_FAILURE 1 + void* malloc(size_t) __MALLOC; void free(void*); void* calloc(size_t nmemb, size_t); diff --git a/LibC/string.cpp b/LibC/string.cpp index 36be3fcb8a8..f63b535d692 100644 --- a/LibC/string.cpp +++ b/LibC/string.cpp @@ -90,15 +90,16 @@ int memcmp(const void* v1, const void* v2, size_t n) return 0; } -void memcpy(void* dest, const void* src, size_t n) +void* memcpy(void* dest, const void* src, size_t n) { auto* bdest = (unsigned char*)dest; auto* bsrc = (const unsigned char*)src; for (; n; --n) *(bdest++) = *(bsrc++); + return dest; } -void memmove(void* dest, const void* src, size_t n) +void* memmove(void* dest, const void* src, size_t n) { if (dest < src) return memcpy(dest, src, n); diff --git a/LibC/string.h b/LibC/string.h index c121dfc8620..316cd944b0f 100644 --- a/LibC/string.h +++ b/LibC/string.h @@ -9,8 +9,8 @@ size_t strlen(const char*); int strcmp(const char*, const char*); int strncmp(const char*, const char*, size_t); int memcmp(const void*, const void*, size_t); -void memcpy(void*, const void*, size_t); -void memmove(void*, const void*, size_t); +void* memcpy(void*, const void*, size_t); +void* memmove(void*, const void*, size_t); void bzero(void*, size_t); void bcopy(const void*, void*, size_t); void* memset(void*, int, size_t); diff --git a/LibC/sys/cdefs.h b/LibC/sys/cdefs.h index 05dc28aa56e..e26352ee82e 100644 --- a/LibC/sys/cdefs.h +++ b/LibC/sys/cdefs.h @@ -17,6 +17,8 @@ #undef __P #define __P(a) a +#define offsetof(type, member) __builtin_offsetof(type, member) + #ifdef __cplusplus extern "C" int main(int, char**); #endif diff --git a/LibC/sys/sysmacros.h b/LibC/sys/sysmacros.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/LibC/unistd.cpp b/LibC/unistd.cpp index 462e3af940f..d8191ae5079 100644 --- a/LibC/unistd.cpp +++ b/LibC/unistd.cpp @@ -274,4 +274,24 @@ int mknod(const char* pathname, mode_t, dev_t) assert(false); } +long fpathconf(int fd, int name) +{ + (void) fd; + (void) name; + assert(false); +} + +long pathconf(const char* path, int name) +{ + (void) path; + (void) name; + assert(false); +} + +void _exit(int status) +{ + Syscall::invoke(Syscall::SC_exit, (dword)status); + assert(false); +} + } diff --git a/LibC/unistd.h b/LibC/unistd.h index 6246041ab7c..b11d90708af 100644 --- a/LibC/unistd.h +++ b/LibC/unistd.h @@ -11,6 +11,7 @@ extern char** environ; inline int getpagesize() { return 4096; } pid_t fork(); int execve(const char* filename, const char** argv, const char** envp); +void _exit(int status); pid_t getsid(pid_t); pid_t setsid(); int setpgid(pid_t pid, pid_t pgid); @@ -52,6 +53,12 @@ unsigned int alarm(unsigned int seconds); int access(const char* pathname, int mode); int isatty(int fd); int mknod(const char* pathname, mode_t, dev_t); +long fpathconf(int fd, int name); +long pathconf(const char *path, int name); + +enum { + _PC_NAME_MAX, +}; #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) #define WTERMSIG(status) ((status) & 0x7f) @@ -82,6 +89,9 @@ int mknod(const char* pathname, mode_t, dev_t); #define S_IWOTH 0002 #define S_IXOTH 0001 +#define S_IRWXG (S_IRWXU >> 3) +#define S_IRWXO (S_IRWXG >> 3) + #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) @@ -89,18 +99,5 @@ int mknod(const char* pathname, mode_t, dev_t); #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#define O_CREAT 0100 -#define O_EXCL 0200 -#define O_NOCTTY 0400 -#define O_TRUNC 01000 -#define O_APPEND 02000 -#define O_NONBLOCK 04000 -#define O_DIRECTORY 00200000 -#define O_NOFOLLOW 00400000 -#define O_CLOEXEC 02000000 - __END_DECLS diff --git a/LibC/utime.h b/LibC/utime.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/LibC/utmp.h b/LibC/utmp.h new file mode 100644 index 00000000000..69e1167e82b --- /dev/null +++ b/LibC/utmp.h @@ -0,0 +1,40 @@ +#pragma once + +#include + +__BEGIN_DECLS + +struct exit_status { /* Type for ut_exit, below */ + short int e_termination; /* Process termination status */ + short int e_exit; /* Process exit status */ +}; + +#define UT_NAMESIZE 32 +#define UT_LINESIZE 32 +#define UT_HOSTSIZE 256 + +struct utmp { + short ut_type; /* Type of record */ + pid_t ut_pid; /* PID of login process */ + char ut_line[UT_LINESIZE]; /* Device name of tty - "/dev/" */ + char ut_id[4]; /* Terminal name suffix, + or inittab(5) ID */ + char ut_user[UT_NAMESIZE]; /* Username */ + char ut_host[UT_HOSTSIZE]; /* Hostname for remote login, or + kernel version for run-level + messages */ + struct exit_status ut_exit; /* Exit status of a process + marked as DEAD_PROCESS; not + used by Linux init (1 */ + + long ut_session; /* Session ID */ + struct timeval ut_tv; /* Time entry was made */ + + int32_t ut_addr_v6[4]; /* Internet address of remote + host; IPv4 address uses + just ut_addr_v6[0] */ + + char __unused[20]; /* Reserved for future use */ +}; + +__END_DECLS diff --git a/Userland/cat.cpp b/Userland/cat.cpp index 04453054f81..4a5162a41a6 100644 --- a/Userland/cat.cpp +++ b/Userland/cat.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include int main(int argc, char** argv) diff --git a/Userland/mm.cpp b/Userland/mm.cpp index 2be82fce9c5..1e49f9a0113 100644 --- a/Userland/mm.cpp +++ b/Userland/mm.cpp @@ -1,5 +1,6 @@ -#include -#include +#include +#include +#include int main(int argc, char** argv) { diff --git a/Userland/ps.cpp b/Userland/ps.cpp index f36f1a224b4..6b18f3a0f13 100644 --- a/Userland/ps.cpp +++ b/Userland/ps.cpp @@ -1,5 +1,6 @@ -#include -#include +#include +#include +#include int main(int argc, char** argv) { diff --git a/Userland/sh.cpp b/Userland/sh.cpp index 85cfed30912..c2065f9d063 100644 --- a/Userland/sh.cpp +++ b/Userland/sh.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include