diff options
author | Anton Kling <anton@kling.gg> | 2023-11-23 00:52:35 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-23 00:52:35 +0100 |
commit | 81819f711e6d1f9216f688da8ecbbc682d106d9c (patch) | |
tree | 0f0df7c43cc5bc956c2c067e55766bfa90823a7f /userland | |
parent | ec91e81a4fcfd7ee6bc4150f06d8740e82f808da (diff) |
LibC: Reduce warnings in code
Diffstat (limited to 'userland')
36 files changed, 85 insertions, 56 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile index 10be0b7..4c784fe 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 -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 +CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -Werror -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type +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 math/min.o math/max.o all: libc.a %.o: %.c diff --git a/userland/libc/dirent/readdir.c b/userland/libc/dirent/readdir.c index 88aff48..8b825cb 100644 --- a/userland/libc/dirent/readdir.c +++ b/userland/libc/dirent/readdir.c @@ -1,4 +1,5 @@ #include <dirent.h> +#include <unistd.h> struct dirent *readdir(DIR *dir) { size_t offset = dir->dir_num * sizeof(struct dirent); @@ -6,7 +7,7 @@ struct dirent *readdir(DIR *dir) { if (-1 == (rc = pread(dir->fd, &dir->internal_direntry, sizeof(struct dirent), offset))) return NULL; - if (rc < sizeof(struct dirent)) + if (rc < (int)sizeof(struct dirent)) return NULL; dir->dir_num++; diff --git a/userland/libc/include/math.h b/userland/libc/include/math.h index e69de29..dbb94e7 100644 --- a/userland/libc/include/math.h +++ b/userland/libc/include/math.h @@ -0,0 +1,2 @@ +int max(int a, int b); +int min(int a, int b); diff --git a/userland/libc/include/stdio.h b/userland/libc/include/stdio.h index 8ac4e59..be8629d 100644 --- a/userland/libc/include/stdio.h +++ b/userland/libc/include/stdio.h @@ -120,4 +120,5 @@ char *tmpnam(char *s); int rename(const char *old, const char *new); size_t getdelim(char **lineptr, size_t *n, int delimiter, FILE *stream); size_t getline(char **lineptr, size_t *n, FILE *stream); +int vfscanf(FILE *stream, const char *format, va_list ap); #endif diff --git a/userland/libc/include/string.h b/userland/libc/include/string.h index 0c61efa..65d0796 100644 --- a/userland/libc/include/string.h +++ b/userland/libc/include/string.h @@ -26,4 +26,5 @@ int strncasecmp(const char *s1, const char *s2, size_t n); int strcasecmp(const char *s1, const char *s2); char *strtok(char *restrict s, const char *restrict sep); char *strcat(char *restrict s1, const char *restrict s2); +int memcmp(const void *s1, const void *s2, size_t n); #endif diff --git a/userland/libc/include/sys/wait.h b/userland/libc/include/sys/wait.h index e69de29..cdfa252 100644 --- a/userland/libc/include/sys/wait.h +++ b/userland/libc/include/sys/wait.h @@ -0,0 +1 @@ +int wait(int *stat_loc); diff --git a/userland/libc/include/unistd.h b/userland/libc/include/unistd.h index e47f6eb..ccfec5e 100644 --- a/userland/libc/include/unistd.h +++ b/userland/libc/include/unistd.h @@ -26,4 +26,6 @@ uint32_t uptime(void); // not standard int chdir(const char *path); char *getcwd(char *buf, size_t size); int isatty(int fd); +int pread(int fd, void *buf, size_t count, size_t offset); +int fork(void); #endif diff --git a/userland/libc/libc.c b/userland/libc/libc.c index 5fcf9fa..7320d29 100644 --- a/userland/libc/libc.c +++ b/userland/libc/libc.c @@ -2,6 +2,7 @@ #include <errno.h> #include <fcntl.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <syscall.h> @@ -141,7 +142,8 @@ void _libc_setup(void) { // Syscall: eax ebx ecx edx esi edi int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx, uint32_t esi, uint32_t edi) { - asm volatile("push %edi\n" + asm volatile( + "push %edi\n" "push %esi\n" "push %ebx\n" "mov 0x1C(%ebp), %edi\n" @@ -156,7 +158,7 @@ int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx, "pop %edi\n"); } -int pipe(int fd[2]) { return syscall(SYS_PIPE, fd, 0, 0, 0, 0); } +int pipe(int fd[2]) { return syscall(SYS_PIPE, (u32)fd, 0, 0, 0, 0); } // https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html char *strerror(int errnum) { @@ -199,14 +201,14 @@ int open(const char *file, int flags, ...) { .flags = flags, .mode = mode, }; - RC_ERRNO(syscall(SYS_OPEN, &args, 0, 0, 0, 0)); + RC_ERRNO(syscall(SYS_OPEN, (u32)&args, 0, 0, 0, 0)); } -int close(int fd) { return syscall(SYS_CLOSE, (void *)fd, 0, 0, 0, 0); } +int close(int fd) { return syscall(SYS_CLOSE, (u32)fd, 0, 0, 0, 0); } int execv(char *path, char **argv) { struct SYS_EXEC_PARAMS args = {.path = path, .argv = argv}; - return syscall(SYS_EXEC, &args, 0, 0, 0, 0); + return syscall(SYS_EXEC, (u32)&args, 0, 0, 0, 0); } /* int syscall(int sys, void *args) { @@ -239,12 +241,12 @@ int pwrite(int fd, const char *buf, size_t count, size_t offset) { .count = count, .offset = offset, }; - return syscall(SYS_PWRITE, &args, 0, 0, 0, 0); + return syscall(SYS_PWRITE, (u32)&args, 0, 0, 0, 0); } -int wait(int *stat_loc) { return syscall(SYS_WAIT, stat_loc, 0, 0, 0, 0); } +int wait(int *stat_loc) { return syscall(SYS_WAIT, (u32)stat_loc, 0, 0, 0, 0); } -void exit(int status) { syscall(SYS_EXIT, (void *)status, 0, 0, 0, 0); } +void exit(int status) { syscall(SYS_EXIT, (u32)status, 0, 0, 0, 0); } int pread(int fd, void *buf, size_t count, size_t offset) { struct SYS_PREAD_PARAMS args = { @@ -253,7 +255,7 @@ int pread(int fd, void *buf, size_t count, size_t offset) { .count = count, .offset = offset, }; - RC_ERRNO(syscall(SYS_PREAD, &args, 0, 0, 0, 0)); + RC_ERRNO(syscall(SYS_PREAD, (u32)&args, 0, 0, 0, 0)); } int read(int fd, void *buf, size_t count) { @@ -262,7 +264,7 @@ int read(int fd, void *buf, size_t count) { .buf = buf, .count = count, }; - RC_ERRNO(syscall(SYS_READ, &args, 0, 0, 0, 0)); + RC_ERRNO(syscall(SYS_READ, (u32)&args, 0, 0, 0, 0)); } int dup2(int org_fd, int new_fd) { @@ -270,7 +272,7 @@ int dup2(int org_fd, int new_fd) { .org_fd = org_fd, .new_fd = new_fd, }; - RC_ERRNO(syscall(SYS_DUP2, &args, 0, 0, 0, 0)); + RC_ERRNO(syscall(SYS_DUP2, (u32)&args, 0, 0, 0, 0)); } int fork(void) { return s_syscall(SYS_FORK); } @@ -289,7 +291,7 @@ int poll(struct pollfd *fds, size_t nfds, int timeout) { .nfds = nfds, .timeout = timeout, }; - RC_ERRNO(syscall(SYS_POLL, &args, 0, 0, 0, 0)); + RC_ERRNO(syscall(SYS_POLL, (u32)&args, 0, 0, 0, 0)); } int socket(int domain, int type, int protocol) { @@ -298,7 +300,7 @@ int socket(int domain, int type, int protocol) { .type = type, .protocol = protocol, }; - RC_ERRNO(syscall(SYS_SOCKET, &args, 0, 0, 0, 0)); + RC_ERRNO(syscall(SYS_SOCKET, (u32)&args, 0, 0, 0, 0)); } int accept(int socket, struct sockaddr *address, socklen_t *address_len) { @@ -307,7 +309,7 @@ int accept(int socket, struct sockaddr *address, socklen_t *address_len) { .address = address, .address_len = address_len, }; - RC_ERRNO(syscall(SYS_ACCEPT, &args, 0, 0, 0, 0)); + RC_ERRNO(syscall(SYS_ACCEPT, (u32)&args, 0, 0, 0, 0)); } int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { @@ -316,7 +318,7 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { .addr = addr, .addrlen = addrlen, }; - RC_ERRNO(syscall(SYS_BIND, &args, 0, 0, 0, 0)); + RC_ERRNO(syscall(SYS_BIND, (u32)&args, 0, 0, 0, 0)); } int shm_open(const char *name, int oflag, mode_t mode) { @@ -325,5 +327,5 @@ int shm_open(const char *name, int oflag, mode_t mode) { .oflag = oflag, .mode = mode, }; - RC_ERRNO(syscall(SYS_SHM_OPEN, &args, 0, 0, 0, 0)); + RC_ERRNO(syscall(SYS_SHM_OPEN, (u32)&args, 0, 0, 0, 0)); } diff --git a/userland/libc/malloc/malloc.c b/userland/libc/malloc/malloc.c index 5c2fe98..4c9621b 100644 --- a/userland/libc/malloc/malloc.c +++ b/userland/libc/malloc/malloc.c @@ -1,6 +1,7 @@ #include <assert.h> #include <errno.h> #include <malloc/malloc.h> +#include <math.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> @@ -21,10 +22,6 @@ typedef struct MallocHeader { struct MallocHeader *n; } MallocHeader; -size_t max(size_t a, size_t b) { return (a > b) ? a : b; } - -//;size_t min(size_t a, size_t b) { return (a < b) ? a : b; } - uint64_t delta_page(uint64_t a) { return 0x1000 - (a % 0x1000); } MallocHeader *head = NULL; @@ -117,12 +114,6 @@ void merge_headers(MallocHeader *b) { if (!n) return; - if (n > 0xf58c0820 - 0x8 && n < 0xf58c0820 + 0x8) { - printf("b: %x\n", b); - printf("b->n: %x\n", b->n); - asm("hlt"); - assert(0); - } if (!(n->flags & IS_FREE)) return; @@ -199,7 +190,7 @@ void *calloc(size_t nelem, size_t elsize) { size_t get_mem_size(void *ptr) { if (!ptr) return 0; - return ((MallocHeader *)(ptr - sizeof(MallocHeader)))->size; + return ((MallocHeader *)((u32)ptr - sizeof(MallocHeader)))->size; } void *realloc(void *ptr, size_t size) { diff --git a/userland/libc/pty.c b/userland/libc/pty.c index b7ddf00..17b91de 100644 --- a/userland/libc/pty.c +++ b/userland/libc/pty.c @@ -11,5 +11,5 @@ int openpty(int *amaster, int *aslave, char *name, .termp = termp, .winp = winp, }; - syscall(SYS_OPENPTY, &args, 0, 0, 0, 0); + return syscall(SYS_OPENPTY, &args, 0, 0, 0, 0); } diff --git a/userland/libc/stdio/fopen.c b/userland/libc/stdio/fopen.c index 6a3f374..d31082d 100644 --- a/userland/libc/stdio/fopen.c +++ b/userland/libc/stdio/fopen.c @@ -1,6 +1,7 @@ #include <fcntl.h> #include <stdint.h> #include <stdio.h> +#include <stdlib.h> #include <sys/stat.h> // FIXME: All modes not implemented @@ -8,7 +9,7 @@ FILE *fopen(const char *pathname, const char *mode) { uint8_t read = 0; uint8_t write = 0; - uint8_t append = 0; +// uint8_t append = 0; // FIXME: Not parsed correctly for (; *mode; mode++) { // r or rb @@ -26,7 +27,7 @@ FILE *fopen(const char *pathname, const char *mode) { write = 1; break; case 'a': - append = 1; +// append = 1; break; } } diff --git a/userland/libc/stdio/open_memstream.c b/userland/libc/stdio/open_memstream.c index 8f359b9..0d3df86 100644 --- a/userland/libc/stdio/open_memstream.c +++ b/userland/libc/stdio/open_memstream.c @@ -1,4 +1,5 @@ #include <assert.h> +#include <math.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> @@ -34,7 +35,7 @@ size_t memstream_write(FILE *fp, const unsigned char *buf, size_t n) { memcpy(c->buffer + fp->offset_in_file, buf, n); fp->offset_in_file += n; - if (fp->offset_in_file > c->buffer_usage) + if (fp->offset_in_file > (long)c->buffer_usage) c->buffer_usage = fp->offset_in_file; return n; } diff --git a/userland/libc/stdio/remove.c b/userland/libc/stdio/remove.c index 35b41ad..39f8af2 100644 --- a/userland/libc/stdio/remove.c +++ b/userland/libc/stdio/remove.c @@ -3,6 +3,7 @@ extern int errno; int remove(const char *path) { + (void)path; // FIXME errno = ENAMETOOLONG; return -1; diff --git a/userland/libc/stdio/rename.c b/userland/libc/stdio/rename.c index 15d4bf5..a02cacb 100644 --- a/userland/libc/stdio/rename.c +++ b/userland/libc/stdio/rename.c @@ -1,8 +1,9 @@ -#include <stdio.h> #include <assert.h> +#include <stdio.h> int rename(const char *old, const char *new) { - (void)old; - (void)new; + (void)old; + (void)new; assert(0); // TODO: Implement - } + return 0; +} diff --git a/userland/libc/stdio/stdin.c b/userland/libc/stdio/stdin.c index c424cc5..bc5c6f2 100644 --- a/userland/libc/stdio/stdin.c +++ b/userland/libc/stdio/stdin.c @@ -1,9 +1,11 @@ #include <assert.h> +#include <math.h> #include <stdio.h> +#include <stdlib.h> #include <unistd.h> size_t raw_write_fd(FILE *f, const unsigned char *s, size_t l) { - int rc = pwrite(f->fd, s, l, f->offset_in_file); + int rc = pwrite(f->fd, (char *)s, l, f->offset_in_file); if (rc == -1) { f->has_error = 1; return 0; @@ -84,6 +86,7 @@ size_t read_fd(FILE *f, unsigned char *s, size_t l) { return read_fd(f, s, l); } assert(0); + return 0; } int seek_fd(FILE *stream, long offset, int whence) { diff --git a/userland/libc/stdio/tmpnam.c b/userland/libc/stdio/tmpnam.c index aafe67d..3fe93fa 100644 --- a/userland/libc/stdio/tmpnam.c +++ b/userland/libc/stdio/tmpnam.c @@ -1,5 +1,7 @@ #include <assert.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> char *tmpnam(char *s) { assert(!s); diff --git a/userland/libc/stdio/vfprintf.c b/userland/libc/stdio/vfprintf.c index b2d4902..c3a8de7 100644 --- a/userland/libc/stdio/vfprintf.c +++ b/userland/libc/stdio/vfprintf.c @@ -2,6 +2,7 @@ #include <stddef.h> #include <stdint.h> #include <stdio.h> +#include <string.h> const char HEX_SET[0x10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; diff --git a/userland/libc/stdlib/abort.c b/userland/libc/stdlib/abort.c index 7fd747e..90368a9 100644 --- a/userland/libc/stdlib/abort.c +++ b/userland/libc/stdlib/abort.c @@ -1,5 +1,6 @@ #include <assert.h> #include <stdlib.h> +#include <stdio.h> // https://pubs.opengroup.org/onlinepubs/9699919799/functions/abort.html void abort(void) { diff --git a/userland/libc/stdlib/getenv.c b/userland/libc/stdlib/getenv.c index 9a6a4e5..13d871c 100644 --- a/userland/libc/stdlib/getenv.c +++ b/userland/libc/stdlib/getenv.c @@ -1,6 +1,7 @@ #include <stdlib.h> char *getenv(const char *name) { + (void)name; // FIXME return NULL; } diff --git a/userland/libc/stdlib/realpath.c b/userland/libc/stdlib/realpath.c index 438ed8d..5589032 100644 --- a/userland/libc/stdlib/realpath.c +++ b/userland/libc/stdlib/realpath.c @@ -1,6 +1,7 @@ #include <assert.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> // FIXME: This is nowhere near complete char *realpath(const char *filename, char *resolvedname) { diff --git a/userland/libc/stdlib/strtol.c b/userland/libc/stdlib/strtol.c index 7aa7760..09a5ad7 100644 --- a/userland/libc/stdlib/strtol.c +++ b/userland/libc/stdlib/strtol.c @@ -1,7 +1,8 @@ +#include <assert.h> +#include <ctype.h> #include <errno.h> #include <limits.h> #include <stdlib.h> -#include <assert.h> extern int errno; extern int get_value(char c, long base); @@ -10,17 +11,17 @@ extern int get_value(char c, long base); long strtol(const char *str, char **restrict endptr, int base) { long ret_value = 0; if (endptr) - *endptr = str; + *endptr = (char *)str; // Ignore inital white-space sequence for (; *str && isspace(*str); str++) ; if (!*str) return ret_value; - int sign = 0; + // int sign = 0; if ('-' == *str) { // FIXME - sign = 1; + // sign = 1; str++; assert(0); } else if ('+' == *str) { @@ -47,6 +48,6 @@ long strtol(const char *str, char **restrict endptr, int base) { return 0; } if (endptr) - *endptr = str; + *endptr = (char*)str; return ret_value; } diff --git a/userland/libc/stdlib/strtoul.c b/userland/libc/stdlib/strtoul.c index 4d9a51d..c490aeb 100644 --- a/userland/libc/stdlib/strtoul.c +++ b/userland/libc/stdlib/strtoul.c @@ -1,7 +1,8 @@ #include <assert.h> +#include <ctype.h> #include <errno.h> -#include <stdlib.h> #include <limits.h> +#include <stdlib.h> extern int errno; int get_value(char c, long base) { @@ -24,17 +25,17 @@ unsigned long strtoul(const char *restrict str, char **restrict endptr, int base) { unsigned long ret_value = 0; if (endptr) - *endptr = str; + *endptr = (char *)str; // Ignore inital white-space sequence for (; *str && isspace(*str); str++) ; if (!*str) return ret_value; - int sign = 0; + // int sign = 0; if ('-' == *str) { // FIXME - sign = 1; + // sign = 1; str++; assert(0); } else if ('+' == *str) { @@ -67,6 +68,6 @@ unsigned long strtoul(const char *restrict str, char **restrict endptr, return 0; } if (endptr) - *endptr = str; + *endptr = (char*)str; return ret_value; } diff --git a/userland/libc/stdlib/system.c b/userland/libc/stdlib/system.c index d951c5c..1cba966 100644 --- a/userland/libc/stdlib/system.c +++ b/userland/libc/stdlib/system.c @@ -1,4 +1,6 @@ #include <stdlib.h> +#include <unistd.h> +#include <sys/wait.h> int system(const char *command) { if (!command) @@ -7,7 +9,7 @@ int system(const char *command) { if (0 == pid) { char *argv[2]; argv[0] = "/sh"; - argv[1] = command; + argv[1] = (char *)command; execv("/sh", argv); } // FIXME: Use waitpid diff --git a/userland/libc/string/strcasecmp.c b/userland/libc/string/strcasecmp.c index eed337b..6420dbf 100644 --- a/userland/libc/string/strcasecmp.c +++ b/userland/libc/string/strcasecmp.c @@ -1,3 +1,4 @@ +#include <ctype.h> #include <strings.h> int strcasecmp(const char *s1, const char *s2) { diff --git a/userland/libc/string/strncasecmp.c b/userland/libc/string/strncasecmp.c index 9ce8c04..c635a03 100644 --- a/userland/libc/string/strncasecmp.c +++ b/userland/libc/string/strncasecmp.c @@ -1,4 +1,5 @@ #include <strings.h> +#include <ctype.h> #include <stddef.h> int strncasecmp(const char *s1, const char *s2, size_t n) { diff --git a/userland/libc/string/strndup.c b/userland/libc/string/strndup.c index ffb2088..22d6303 100644 --- a/userland/libc/string/strndup.c +++ b/userland/libc/string/strndup.c @@ -1,6 +1,7 @@ #include <stddef.h> #include <stdlib.h> #include <string.h> +#include <math.h> // The strndup() function shall be equivalent to the strdup() function, // duplicating the provided s in a new block of memory allocated as if diff --git a/userland/libc/string/strpbrk.c b/userland/libc/string/strpbrk.c index fb16b0c..3bb058b 100644 --- a/userland/libc/string/strpbrk.c +++ b/userland/libc/string/strpbrk.c @@ -4,7 +4,7 @@ char *strpbrk(const char *s1, const char *s2) { for (; *s1; s1++) { for (const char *t = s2; *t; t++) { if (*s1 == *t) { - return s1; + return (char*)s1; } } } diff --git a/userland/libc/string/strstr.c b/userland/libc/string/strstr.c index 20b9dc2..9de0954 100644 --- a/userland/libc/string/strstr.c +++ b/userland/libc/string/strstr.c @@ -3,7 +3,7 @@ char *strstr(const char *s1, const char *s2) { // If s2 points to a string with zero length, the function shall return s1. if ('\0' == *s2) - return s1; + return (char*)s1; for (; *s1; s1++) { const char *t1 = s1; const char *t2 = s2; @@ -15,7 +15,7 @@ char *strstr(const char *s1, const char *s2) { } } if (!is_dif) - return s1; + return (char*)s1; } return NULL; } diff --git a/userland/libc/sys/stat/mkdir.c b/userland/libc/sys/stat/mkdir.c index 927afd8..ca10c30 100644 --- a/userland/libc/sys/stat/mkdir.c +++ b/userland/libc/sys/stat/mkdir.c @@ -2,5 +2,5 @@ #include <syscall.h> int mkdir(const char *path, mode_t mode) { - return syscall(SYS_MKDIR, (void *)path, (void *)mode, 0, 0, 0); + return syscall(SYS_MKDIR, (u32)path, (u32)mode, 0, 0, 0); } diff --git a/userland/libc/time/clock_gettime.c b/userland/libc/time/clock_gettime.c index 15f0cb7..492b968 100644 --- a/userland/libc/time/clock_gettime.c +++ b/userland/libc/time/clock_gettime.c @@ -2,6 +2,7 @@ #include <time.h> int clock_gettime(clockid_t clock_id, struct timespec *tp) { + (void)clock_id; tp->tv_sec = 0; tp->tv_nsec = 0; return 0; diff --git a/userland/libc/time/gmtime.c b/userland/libc/time/gmtime.c index 44e0ff3..08af482 100644 --- a/userland/libc/time/gmtime.c +++ b/userland/libc/time/gmtime.c @@ -16,6 +16,7 @@ struct tm gmtime_r = { // https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime.html struct tm *gmtime(const time_t *timer) { + (void)timer; // TODO: Implement return &gmtime_r; } diff --git a/userland/libc/time/localtime.c b/userland/libc/time/localtime.c index 40ca351..8ad74d8 100644 --- a/userland/libc/time/localtime.c +++ b/userland/libc/time/localtime.c @@ -16,6 +16,7 @@ // https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime.html struct tm *localtime(const time_t *timer) { + (void)timer; // TODO: Implement return &localtime_r; } diff --git a/userland/libc/unistd/execvp.c b/userland/libc/unistd/execvp.c index 573e822..e38b4b7 100644 --- a/userland/libc/unistd/execvp.c +++ b/userland/libc/unistd/execvp.c @@ -1,8 +1,8 @@ -#include <unistd.h> #include <syscall.h> +#include <unistd.h> // FIXME: Path resolution int execvp(const char *file, char *const argv[]) { - struct SYS_EXEC_PARAMS args = {.path = file, .argv = argv}; + struct SYS_EXEC_PARAMS args = {.path = file, .argv = (char **)argv}; return syscall(SYS_EXEC, &args, 0, 0, 0, 0); } diff --git a/userland/libc/unistd/getopt.c b/userland/libc/unistd/getopt.c index a026b59..5b13d16 100644 --- a/userland/libc/unistd/getopt.c +++ b/userland/libc/unistd/getopt.c @@ -6,6 +6,9 @@ char *optarg; // https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html int getopt(int argc, char *const argv[], const char *optstring) { + (void)argc; + (void)argv; + (void)optstring; // TODO optind = 1; optarg = NULL; diff --git a/userland/libc/unistd/unlink.c b/userland/libc/unistd/unlink.c index ccac0df..7d7aa1c 100644 --- a/userland/libc/unistd/unlink.c +++ b/userland/libc/unistd/unlink.c @@ -1,4 +1,5 @@ #include <unistd.h> +#include <stdio.h> int unlink(const char *path) { // TODO diff --git a/userland/minibox/utilities/sh/sh.c b/userland/minibox/utilities/sh/sh.c index 590e489..3a29302 100644 --- a/userland/minibox/utilities/sh/sh.c +++ b/userland/minibox/utilities/sh/sh.c @@ -49,6 +49,7 @@ int execute_binary(struct AST *ast, int input_fd) { dup2(file_out_fd, ast->file_out_fd_to_use); execvp(program, argv); + perror("execvp"); exit(1); } if (ast->file_out) |