summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-18 16:47:36 +0200
committerAnton Kling <anton@kling.gg>2024-04-18 16:47:36 +0200
commit568a0b7017e8e779731325083015907b006866c3 (patch)
treeae2f78d7fee945a90e29eb3eb71024be43077d76 /userland
parentcc2b68cb26738dce0c7696ca0fe5b0cd8b24c171 (diff)
LibC: Fix compiler warnings
It can now compile with almost all compiler warnings turned on without producing any warnings.
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/Makefile3
-rw-r--r--userland/libc/include/tb/sb.h2
-rw-r--r--userland/libc/libc.c4
-rw-r--r--userland/libc/malloc/malloc.c8
-rw-r--r--userland/libc/sys/stat/stat.c1
-rw-r--r--userland/libc/tb/sb.c2
-rw-r--r--userland/libc/tb/sv.c1
7 files changed, 11 insertions, 10 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile
index b7e14a7..e2689ca 100644
--- a/userland/libc/Makefile
+++ b/userland/libc/Makefile
@@ -1,8 +1,7 @@
CC="i686-sb-gcc"
AR="i686-sb-ar"
AS="i686-sb-as"
-#CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type
-CFLAGS = -ggdb -ffreestanding -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type
+CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -pedantic -Werror -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter
OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.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 systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o fcntl/open_process.o tb/sb.o tb/sv.o string/memchr.o stdlib/atol.o stdlib/atoll.o stdlib/strtoll.o sys/stat/fstat.o
all: libc.a
diff --git a/userland/libc/include/tb/sb.h b/userland/libc/include/tb/sb.h
index 5675985..84f8161 100644
--- a/userland/libc/include/tb/sb.h
+++ b/userland/libc/include/tb/sb.h
@@ -16,7 +16,7 @@ void sb_free(struct sb *ctx);
void sb_reset(struct sb *ctx);
int sb_isempty(const struct sb *ctx);
void sb_append_char(struct sb *ctx, char c);
-int sb_delete_right(struct sb *ctx, int n);
+int sb_delete_right(struct sb *ctx, size_t n);
void sb_append(struct sb *ctx, const char *s);
void sb_append_sv(struct sb *ctx, struct sv sv);
void sb_prepend_sv(struct sb *ctx, struct sv sv);
diff --git a/userland/libc/libc.c b/userland/libc/libc.c
index 70c7e70..8129448 100644
--- a/userland/libc/libc.c
+++ b/userland/libc/libc.c
@@ -223,10 +223,6 @@ int fork(void) {
return s_syscall(SYS_FORK);
}
-void dputc(int fd, const char c) {
- pwrite(fd, &c, 1, 0);
-}
-
int brk(void *addr) {
return syscall(SYS_BRK, addr, 0, 0, 0, 0);
}
diff --git a/userland/libc/malloc/malloc.c b/userland/libc/malloc/malloc.c
index bd880b8..19fc91e 100644
--- a/userland/libc/malloc/malloc.c
+++ b/userland/libc/malloc/malloc.c
@@ -2,8 +2,12 @@
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <sys/random.h>
#include <typedefs.h>
+#include <unistd.h>
#define NEW_ALLOC_SIZE 0x5000
#define IS_FREE (1 << 0)
@@ -27,7 +31,7 @@ u32 total_heap_size = 0;
// printf without using malloc() so that it can be used internally by
// malloc() such that it does not have a stack overflow.
int debug_vprintf(const char *fmt, va_list ap) {
- const char buffer[4096];
+ char buffer[4096];
int rc = vsnprintf(buffer, 4096, fmt, ap);
if (0 > rc) {
return -1;
@@ -188,7 +192,7 @@ void *int_malloc(size_t s, int recursion) {
free_entry->flags = 0;
free_entry->n = new_entry;
free_entry->magic = 0xdde51ab9410268b1;
- randomfill(rc, s);
+ randomfill(rc, s);
return rc;
}
diff --git a/userland/libc/sys/stat/stat.c b/userland/libc/sys/stat/stat.c
index 00b4f52..21501c2 100644
--- a/userland/libc/sys/stat/stat.c
+++ b/userland/libc/sys/stat/stat.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <sys/stat.h>
#include <syscall.h>
+#include <unistd.h>
int stat(const char *path, struct stat *buf) {
int fd = open(path, O_RDONLY);
diff --git a/userland/libc/tb/sb.c b/userland/libc/tb/sb.c
index 0d0ec52..c3fbc64 100644
--- a/userland/libc/tb/sb.c
+++ b/userland/libc/tb/sb.c
@@ -33,7 +33,7 @@ void sb_append_char(struct sb *ctx, char c) {
ctx->length++;
}
-int sb_delete_right(struct sb *ctx, int n) {
+int sb_delete_right(struct sb *ctx, size_t n) {
n = min(n, ctx->length);
ctx->length -= n;
return n;
diff --git a/userland/libc/tb/sv.c b/userland/libc/tb/sv.c
index 9bffce3..500d041 100644
--- a/userland/libc/tb/sv.c
+++ b/userland/libc/tb/sv.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <tb/sv.h>
+#include <math.h>
char *SV_TO_C(struct sv s) {
char *c_string = malloc(s.length + 1);