diff options
author | Anton Kling <anton@kling.gg> | 2023-11-22 00:47:55 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-22 00:47:55 +0100 |
commit | f3c7d7fbdea1f2bac81909116ddb747a1f8abdf5 (patch) | |
tree | 62a1d998ce11bf4db4343f69dea4e8d231191e48 /userland | |
parent | 24f81104f5ff9cb4ab7db766c53f77fe0e5b86cc (diff) |
Meta: Cleanup of header files such that they are partially shared
The /include directory contains definitons that both the kernel and libc
need to be in sync.
Diffstat (limited to 'userland')
-rw-r--r-- | userland/libc/Makefile | 5 | ||||
-rw-r--r-- | userland/libc/include/stdio.h | 3 | ||||
-rw-r--r-- | userland/libc/include/stdlib.h | 1 | ||||
-rw-r--r-- | userland/libc/include/sys/socket.h | 1 | ||||
-rw-r--r-- | userland/libc/include/sys/stat.h | 31 | ||||
-rw-r--r-- | userland/libc/include/sys/types.h | 28 | ||||
-rw-r--r-- | userland/libc/include/syscall.h | 2 | ||||
-rw-r--r-- | userland/libc/stdio/fread.c | 2 | ||||
-rw-r--r-- | userland/libc/stdio/fwrite.c | 2 | ||||
-rw-r--r-- | userland/libc/stdlib/realpath.c | 61 |
10 files changed, 69 insertions, 67 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile index 6a4b367..10be0b7 100644 --- a/userland/libc/Makefile +++ b/userland/libc/Makefile @@ -1,8 +1,8 @@ CC="i686-sb-gcc" AR="i686-sb-ar" AS="i686-sb-as" -CFLAGS = -ggdb -ffreestanding -O2 -Wall -pedantic -Wimplicit-fallthrough -I./include/ -static -OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o +CFLAGS = -ggdb -ffreestanding -O2 -Wall -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ +OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o all: libc.a %.o: %.c @@ -17,6 +17,7 @@ libc.a: $(OBJ) install: cp crt0.o ../../sysroot/lib/ cp libc.a ../../sysroot/lib/ + cp -r ../../include ../../sysroot/usr/ cp -r include ../../sysroot/usr/ clean: diff --git a/userland/libc/include/stdio.h b/userland/libc/include/stdio.h index aafae78..43700e0 100644 --- a/userland/libc/include/stdio.h +++ b/userland/libc/include/stdio.h @@ -3,6 +3,7 @@ #include <stdarg.h> #include <stddef.h> #include <stdint.h> +#include <sys/types.h> // FIXME: Most of these should probably not be here. But I am too lazy // to fix it right now. This is futures mees problem to deal wth. @@ -56,8 +57,6 @@ extern FILE *__stderr_FILE; #define stdout __stdout_FILE #define stderr __stderr_FILE -typedef int mode_t; - void perror(const char *s); int putchar(int c); diff --git a/userland/libc/include/stdlib.h b/userland/libc/include/stdlib.h index c88f2f3..0c3d0f4 100644 --- a/userland/libc/include/stdlib.h +++ b/userland/libc/include/stdlib.h @@ -29,4 +29,5 @@ int system(const char *command); double atof(const char *str); double strtod(const char *restrict nptr, char **restrict endptr); int atoi(const char *str); +char *realpath(const char *filename, char *resolvedname); #endif diff --git a/userland/libc/include/sys/socket.h b/userland/libc/include/sys/socket.h index c4f10e2..7a2cc23 100644 --- a/userland/libc/include/sys/socket.h +++ b/userland/libc/include/sys/socket.h @@ -7,3 +7,4 @@ size_t recvfrom(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len); size_t sendto(int socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len); +int listen(int socket, int backlog); diff --git a/userland/libc/include/sys/stat.h b/userland/libc/include/sys/stat.h deleted file mode 100644 index 178d014..0000000 --- a/userland/libc/include/sys/stat.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef STAT_H -#define STAT_H -#include <sys/types.h> -#include <time.h> - -struct stat { - dev_t st_dev; // Device ID of device containing file. - ino_t st_ino; // File serial number. - mode_t st_mode; // Mode of file (see below). - nlink_t st_nlink; // Number of hard links to the file. - uid_t st_uid; // User ID of file. - gid_t st_gid; // Group ID of file. - dev_t st_rdev; // Device ID (if file is character or block special). - off_t st_size; // For regular files, the file size in bytes. - // For symbolic links, the length in bytes of the - // pathname contained in the symbolic link. - // For a shared memory object, the length in bytes. - // For a typed memory object, the length in bytes. - // For other file types, the use of this field is - // unspecified. - struct timespec st_atime; // Last data access timestamp. - struct timespec st_mtime; // Last data modification timestamp. - struct timespec st_ctime; // Last file status change timestamp. - blksize_t st_blksize; // A file system-specific preferred I/O block size - // for this object. In some file system types, this - // may vary from file to file. - blkcnt_t st_blocks; // Number of blocks allocated for this object. -}; -int stat(const char *path, struct stat *buf); -int mkdir(const char *path, mode_t mode); -#endif diff --git a/userland/libc/include/sys/types.h b/userland/libc/include/sys/types.h deleted file mode 100644 index 48c57f9..0000000 --- a/userland/libc/include/sys/types.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TYPES_H -#define TYPES_H -typedef unsigned int ino_t; - -typedef int mode_t; - -typedef int nlink_t; -typedef int uid_t; -typedef int gid_t; -typedef int id_t; - -typedef int blkcnt_t; -typedef int off_t; - -typedef int dev_t; -typedef unsigned int fsblkcnt_t; -typedef unsigned int fsfilcnt_t; -typedef unsigned int ino_t; -//typedef unsigned int size_t; - -typedef int blksize_t; -typedef int pid_t; -typedef int ssize_t; - -//typedef int clock_t; -typedef int time_t; -typedef unsigned int suseconds_t; -#endif diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h index 135c669..c09eafb 100644 --- a/userland/libc/include/syscall.h +++ b/userland/libc/include/syscall.h @@ -55,8 +55,6 @@ extern int errno; return c; \ } -typedef int mode_t; - typedef struct SYS_OPEN_PARAMS { const char *file; int flags; diff --git a/userland/libc/stdio/fread.c b/userland/libc/stdio/fread.c index 1a27afa..3d169fc 100644 --- a/userland/libc/stdio/fread.c +++ b/userland/libc/stdio/fread.c @@ -3,7 +3,7 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { // FIXME: Check for overflow - ssize_t bytes_to_read = nmemb * size; + size_t bytes_to_read = nmemb * size; size_t rc = stream->read(stream, ptr, bytes_to_read); // On success, fread() return the number of items read rc /= size; diff --git a/userland/libc/stdio/fwrite.c b/userland/libc/stdio/fwrite.c index 552bbd6..6065465 100644 --- a/userland/libc/stdio/fwrite.c +++ b/userland/libc/stdio/fwrite.c @@ -3,7 +3,7 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { // FIXME: Check for overflow - ssize_t bytes_to_write = nmemb * size; + size_t bytes_to_write = nmemb * size; size_t rc = stream->write(stream, ptr, bytes_to_write); // On success, fwrite() return the number of items // written. diff --git a/userland/libc/stdlib/realpath.c b/userland/libc/stdlib/realpath.c new file mode 100644 index 0000000..438ed8d --- /dev/null +++ b/userland/libc/stdlib/realpath.c @@ -0,0 +1,61 @@ +#include <assert.h> +#include <stdlib.h> +#include <string.h> + +// FIXME: This is nowhere near complete +char *realpath(const char *filename, char *resolvedname) { + assert(resolvedname); + // FIXME: This really should have bounds checking + char cwd[256]; + getcwd(cwd, 256); + strcat(cwd, filename); + const char *path = cwd; + char *result = resolvedname; + // It has to be a absolute path + if ('/' != *path) + return 0; + const char *result_start = result; + int start_directory = 0; + int should_insert_slash = 0; + for (; *path; path++) { + if (start_directory) { + start_directory = 0; + if ('/' == *path) { + path++; + } else if (0 == memcmp(path, "./", 2) || 0 == memcmp(path, ".\0", 2)) { + path++; + } else if (0 == memcmp(path, "../", 3) || 0 == memcmp(path, "..\0", 3)) { + path += 2; + if (result_start + 2 > result) { + // The path is probably something like "/.." or + // "/../foo". A "/.." should become a "/" + // Therefore it skips going back to the parent + if (*path == '/') { + if (result_start == result) + return 0; + result--; + } + } else { + if ('/' != *path) { + should_insert_slash = 1; + } + result--; + result--; + for (; result_start <= result && '/' != *result; result--) + ; + } + } + } + start_directory = ('/' == *path); + if ('\0' == *path) + break; + *result = *path; + result++; + } + if (should_insert_slash) { + *result = '/'; + result++; + } + *result = '\0'; + return 1; +} |