Bladeren bron

Various stubs while trying to get an old coreutils to build.

Andreas Kling 6 jaren geleden
bovenliggende
commit
303577df16
20 gewijzigde bestanden met toevoegingen van 132 en 23 verwijderingen
  1. 1 0
      LibC/dirent.cpp
  2. 1 0
      LibC/errno_numbers.h
  3. 13 0
      LibC/fcntl.h
  4. 11 0
      LibC/limits.h
  5. 15 0
      LibC/locale.h
  6. 1 0
      LibC/stdio.cpp
  7. 2 2
      LibC/stdlib.cpp
  8. 3 0
      LibC/stdlib.h
  9. 3 2
      LibC/string.cpp
  10. 2 2
      LibC/string.h
  11. 2 0
      LibC/sys/cdefs.h
  12. 0 0
      LibC/sys/sysmacros.h
  13. 20 0
      LibC/unistd.cpp
  14. 10 13
      LibC/unistd.h
  15. 0 0
      LibC/utime.h
  16. 40 0
      LibC/utmp.h
  17. 1 0
      Userland/cat.cpp
  18. 3 2
      Userland/mm.cpp
  19. 3 2
      Userland/ps.cpp
  20. 1 0
      Userland/sh.cpp

+ 1 - 0
LibC/dirent.cpp

@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <Kernel/Syscall.h>
 
 extern "C" {

+ 1 - 0
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

+ 13 - 0
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

+ 11 - 0
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

+ 15 - 0
LibC/locale.h

@@ -0,0 +1,15 @@
+#pragma once
+
+#include <sys/cdefs.h>
+
+enum {
+    LC_ALL,
+    LC_NUMERIC,
+};
+
+__BEGIN_DECLS
+
+char* setlocale(int category, const char* locale);
+
+__END_DECLS
+

+ 1 - 0
LibC/stdio.cpp

@@ -7,6 +7,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <Kernel/Syscall.h>
 #include <AK/printf.cpp>
 

+ 2 - 2
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()

+ 3 - 0
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);

+ 3 - 2
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);

+ 2 - 2
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);

+ 2 - 0
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

+ 0 - 0
LibC/sys/sysmacros.h


+ 20 - 0
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);
+}
+
 }

+ 10 - 13
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
 

+ 0 - 0
LibC/utime.h


+ 40 - 0
LibC/utmp.h

@@ -0,0 +1,40 @@
+#pragma once
+
+#include <sys/cdefs.h>
+
+__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

+ 1 - 0
Userland/cat.cpp

@@ -3,6 +3,7 @@
 #include <errno.h>
 #include <string.h>
 #include <stdlib.h>
+#include <fcntl.h>
 #include <assert.h>
 
 int main(int argc, char** argv)

+ 3 - 2
Userland/mm.cpp

@@ -1,5 +1,6 @@
-#include <LibC/stdio.h>
-#include <LibC/unistd.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
 
 int main(int argc, char** argv)
 {

+ 3 - 2
Userland/ps.cpp

@@ -1,5 +1,6 @@
-#include <LibC/stdio.h>
-#include <LibC/unistd.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
 
 int main(int argc, char** argv)
 {

+ 1 - 0
Userland/sh.cpp

@@ -5,6 +5,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <sys/mman.h>
 #include <sys/utsname.h>
 #include <AK/FileSystemPath.h>