From e6584db26da34572fb13aa236e16e19f71c8e976 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 26 Aug 2022 14:16:16 +0200 Subject: user/libc: prepare for OpenED port --- src/user/lib/include/ctype.h | 3 +++ src/user/lib/include/err.h | 0 src/user/lib/include/limits.h | 5 +++++ src/user/lib/include/pwd.h | 0 src/user/lib/include/setjmp.h | 13 +++++++++++++ src/user/lib/include/signal.h | 17 +++++++++++++++++ src/user/lib/include/stdio.h | 27 +++++++++++++++++++++++++++ src/user/lib/include/stdlib.h | 5 +++++ src/user/lib/include/string.h | 2 ++ src/user/lib/include/sys/ioctl.h | 13 +++++++++++++ src/user/lib/include/sys/stat.h | 11 +++++++++++ src/user/lib/include/sys/wait.h | 0 src/user/lib/include/unistd.h | 4 ++++ 13 files changed, 100 insertions(+) create mode 100644 src/user/lib/include/err.h create mode 100644 src/user/lib/include/limits.h create mode 100644 src/user/lib/include/pwd.h create mode 100644 src/user/lib/include/setjmp.h create mode 100644 src/user/lib/include/signal.h create mode 100644 src/user/lib/include/sys/ioctl.h create mode 100644 src/user/lib/include/sys/stat.h create mode 100644 src/user/lib/include/sys/wait.h (limited to 'src/user/lib/include') diff --git a/src/user/lib/include/ctype.h b/src/user/lib/include/ctype.h index 4b15b1d..cbba529 100644 --- a/src/user/lib/include/ctype.h +++ b/src/user/lib/include/ctype.h @@ -6,3 +6,6 @@ int isdigit(int c); int islower(int c); int isspace(int c); int isupper(int c); + +int tolower(int c); +int toupper(int c); diff --git a/src/user/lib/include/err.h b/src/user/lib/include/err.h new file mode 100644 index 0000000..e69de29 diff --git a/src/user/lib/include/limits.h b/src/user/lib/include/limits.h new file mode 100644 index 0000000..065f8e0 --- /dev/null +++ b/src/user/lib/include/limits.h @@ -0,0 +1,5 @@ +#pragma once +#include_next +#include // just for PATH_MAX + +#define _POSIX2_RE_DUP_MAX 255 diff --git a/src/user/lib/include/pwd.h b/src/user/lib/include/pwd.h new file mode 100644 index 0000000..e69de29 diff --git a/src/user/lib/include/setjmp.h b/src/user/lib/include/setjmp.h new file mode 100644 index 0000000..f90bae9 --- /dev/null +++ b/src/user/lib/include/setjmp.h @@ -0,0 +1,13 @@ +#pragma once +#include + +typedef char sigjmp_buf; +static inline int sigsetjmp(sigjmp_buf env, int savemask) { + (void)env; (void)savemask; + return 0; +} + +static inline void siglongjmp(sigjmp_buf env, int val) { + (void)env; (void)val; + __libc_panic("unimplemented"); +} diff --git a/src/user/lib/include/signal.h b/src/user/lib/include/signal.h new file mode 100644 index 0000000..c279beb --- /dev/null +++ b/src/user/lib/include/signal.h @@ -0,0 +1,17 @@ +#pragma once +#include // only for ENOSYS + +#define SIGHUP 0 +#define SIGINT 0 +#define SIGWINCH 0 +#define SIGQUIT 0 +#define SIG_IGN 0 +#define SIG_ERR 0 + +typedef int sig_atomic_t; + +static inline int signal(int sig, void (*func)(int)) { + (void)sig; (void)func; + errno = ENOSYS; + return SIG_ERR; +} diff --git a/src/user/lib/include/stdio.h b/src/user/lib/include/stdio.h index b0d34a7..5ad07e0 100644 --- a/src/user/lib/include/stdio.h +++ b/src/user/lib/include/stdio.h @@ -2,13 +2,20 @@ #include #include #include +#include #define EOF (-1) +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 #define SEEK_SET 1 #define SEEK_CUR 2 #define SEEK_END 3 +#define _IONBF 0 +#define _IOLBF 1 + /* stop fread() from trying to fill the entire buffer before returning * i.e. it will call _syscall_read() exactly once */ #define FEXT_NOFILL 1 @@ -28,15 +35,35 @@ FILE *fopen(const char *path, const char *mode); FILE *freopen(const char *path, const char *mode, FILE *); FILE *fdopen(int fd, const char *mode); FILE *file_clone(const FILE *, const char *mode); +FILE *popen(const char *cmd, const char *mode); +int pclose(FILE *f); + int fextflags(FILE *, int extflags); +int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size); int fclose(FILE *); int fflush(FILE *f); size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restrict); size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restrict); +int fputs(const char *s, FILE *f); char *fgets(char *buf, int size, FILE *f); +int fgetc(FILE *f); +int getc(FILE *f); +int fputc(int c, FILE *f); +int putc(int c, FILE *f); + int fseek(FILE *f, long offset, int whence); +int fseeko(FILE *f, off_t offset, int whence); long ftell(FILE *f); +off_t ftello(FILE *f); int feof(FILE *); int ferror(FILE *); +void clearerr(FILE *f); + +void perror(const char *s); +int puts(const char *s); +int getchar(void); +int putchar(int c); + +off_t lseek(int fd, off_t off, int whence); diff --git a/src/user/lib/include/stdlib.h b/src/user/lib/include/stdlib.h index 7f6630d..e2e3996 100644 --- a/src/user/lib/include/stdlib.h +++ b/src/user/lib/include/stdlib.h @@ -1,8 +1,13 @@ #pragma once #include +#include #ifndef NO_MALLOC_H #include #endif _Noreturn void abort(void); + +int mkstemp(char *template); +char *getenv(const char *name); +int system(const char *cmd); diff --git a/src/user/lib/include/string.h b/src/user/lib/include/string.h index 5cddb61..7235da9 100644 --- a/src/user/lib/include/string.h +++ b/src/user/lib/include/string.h @@ -9,3 +9,5 @@ size_t strcspn(const char *s, const char *reject); char *strtok(char *restrict s, const char *restrict sep); char *strtok_r(char *restrict s, const char *restrict sep, char **restrict state); + +int strncmp(const char *s1, const char *s2, size_t n); diff --git a/src/user/lib/include/sys/ioctl.h b/src/user/lib/include/sys/ioctl.h new file mode 100644 index 0000000..708bc3f --- /dev/null +++ b/src/user/lib/include/sys/ioctl.h @@ -0,0 +1,13 @@ +#pragma once +#include // only for ENOSYS + +#define TIOCGWINSZ 0 +struct winsize { + int ws_row, ws_col; +}; + +static inline int ioctl(int fd, int req, ...) { + (void)fd; (void)req; + errno = ENOSYS; + return -1; +} diff --git a/src/user/lib/include/sys/stat.h b/src/user/lib/include/sys/stat.h new file mode 100644 index 0000000..a954c9b --- /dev/null +++ b/src/user/lib/include/sys/stat.h @@ -0,0 +1,11 @@ +#pragma once +#include // only for ENOSYS + +#define S_ISFIFO(x) 0 + +struct stat {}; +static inline int fstat(int fd, struct stat *sb) { + (void)fd; (void)sb; + errno = ENOSYS; + return -1; +} diff --git a/src/user/lib/include/sys/wait.h b/src/user/lib/include/sys/wait.h new file mode 100644 index 0000000..e69de29 diff --git a/src/user/lib/include/unistd.h b/src/user/lib/include/unistd.h index 9b368dc..1f0c002 100644 --- a/src/user/lib/include/unistd.h +++ b/src/user/lib/include/unistd.h @@ -5,6 +5,10 @@ int fork(void); int close(handle_t h); _Noreturn void exit(int); +_Noreturn void _exit(int); + +int unlink(const char *path); +int isatty(int fd); int execv(const char *path, char *const argv[]); -- cgit v1.2.3