summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sys/stat.h (renamed from kernel/includes/sys/stat.h)3
-rw-r--r--include/sys/types.h (renamed from kernel/includes/sys/types.h)1
-rw-r--r--include/typedefs.h (renamed from kernel/includes/typedefs.h)0
-rw-r--r--kernel/Makefile4
-rw-r--r--kernel/drivers/rtl8139.c6
-rw-r--r--kernel/fs/vfs.c6
-rw-r--r--kernel/network/arp.c7
-rw-r--r--kernel/network/ethernet.c8
-rw-r--r--kernel/network/ipv4.c3
-rw-r--r--kernel/network/tcp.c18
-rw-r--r--kernel/socket.c11
-rw-r--r--kernel/socket.h3
-rw-r--r--userland/libc/Makefile5
-rw-r--r--userland/libc/include/stdio.h3
-rw-r--r--userland/libc/include/stdlib.h1
-rw-r--r--userland/libc/include/sys/socket.h1
-rw-r--r--userland/libc/include/sys/stat.h31
-rw-r--r--userland/libc/include/sys/types.h28
-rw-r--r--userland/libc/include/syscall.h2
-rw-r--r--userland/libc/stdio/fread.c2
-rw-r--r--userland/libc/stdio/fwrite.c2
-rw-r--r--userland/libc/stdlib/realpath.c61
22 files changed, 89 insertions, 117 deletions
diff --git a/kernel/includes/sys/stat.h b/include/sys/stat.h
index 92bb67e..8fc5f25 100644
--- a/kernel/includes/sys/stat.h
+++ b/include/sys/stat.h
@@ -33,4 +33,7 @@ struct stat {
blkcnt_t st_blocks; // Number of blocks allocated for this object.
};
+#ifndef KERNEL
+int stat(const char *path, struct stat *buf);
+#endif
#endif
diff --git a/kernel/includes/sys/types.h b/include/sys/types.h
index f82eff7..26e11b6 100644
--- a/kernel/includes/sys/types.h
+++ b/include/sys/types.h
@@ -12,4 +12,5 @@ typedef i32 gid_t;
typedef u64 off_t;
typedef i64 blksize_t;
typedef i64 blkcnt_t;
+typedef u32 suseconds_t;
#endif
diff --git a/kernel/includes/typedefs.h b/include/typedefs.h
index e290716..e290716 100644
--- a/kernel/includes/typedefs.h
+++ b/include/typedefs.h
diff --git a/kernel/Makefile b/kernel/Makefile
index ce4400e..e2c3db2 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -1,8 +1,8 @@
CC="i686-sb-gcc"
AS="i686-sb-as"
OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o cpu/int_syscall.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o halts.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o
-CFLAGS = -Ofast -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign
-INCLUDE=-I./includes/ -I./libc/include/
+CFLAGS = -O0 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign
+INCLUDE=-I./includes/ -I../include/ -I./libc/include/
all: myos.iso
diff --git a/kernel/drivers/rtl8139.c b/kernel/drivers/rtl8139.c
index cfe5cf2..0ed562e 100644
--- a/kernel/drivers/rtl8139.c
+++ b/kernel/drivers/rtl8139.c
@@ -48,9 +48,7 @@ void handle_packet(void) {
struct PACKET_HEADER packet_header;
packet_header.raw = *buf;
assert(packet_header.data.ROK);
- kprintf("packet_header.raw: %x\n", packet_header.raw);
u16 packet_length = *(buf + 1);
- kprintf("packet_length: %x\n", packet_length);
u8 packet_buffer[8192 + 16];
if (current_packet_read + packet_length >= 8192 + 16) {
@@ -77,14 +75,11 @@ void handle_packet(void) {
__attribute__((interrupt)) void rtl8139_handler(void *regs) {
(void)regs;
u16 status = inw(rtl8139.gen.base_mem_io + 0x3e);
- kprintf("status: %x\n", status);
outw(rtl8139.gen.base_mem_io + 0x3E, 0x5);
if (status & (1 << 2)) {
- kprintf("Packet sent\n");
}
if (status & (1 << 0)) {
- kprintf("Received packet\n");
handle_packet();
}
@@ -118,7 +113,6 @@ void get_mac_address(u8 mac[6]) {
u16 high_mac = inw(base_address + 0x4);
mac_address = ((u64)high_mac << 32) | low_mac;
}
- kprintf("mac_address: %x\n", mac_address);
memcpy(mac, &mac_address, sizeof(u8[6]));
}
diff --git a/kernel/fs/vfs.c b/kernel/fs/vfs.c
index f2fe0a9..214cfd3 100644
--- a/kernel/fs/vfs.c
+++ b/kernel/fs/vfs.c
@@ -291,8 +291,7 @@ int vfs_close(int fd) {
return 0;
}
-int raw_vfs_pread(vfs_fd_t *vfs_fd, void *buf, u64 count,
- u64 offset) {
+int raw_vfs_pread(vfs_fd_t *vfs_fd, void *buf, u64 count, u64 offset) {
if (!(vfs_fd->flags & O_READ))
return -EBADF;
return vfs_fd->inode->read(buf, offset, count, vfs_fd);
@@ -325,8 +324,7 @@ int vfs_pread(int fd, void *buf, u64 count, u64 offset) {
return rc;
}
-int raw_vfs_pwrite(vfs_fd_t *vfs_fd, void *buf, u64 count,
- u64 offset) {
+int raw_vfs_pwrite(vfs_fd_t *vfs_fd, void *buf, u64 count, u64 offset) {
assert(vfs_fd);
assert(vfs_fd->inode);
assert(vfs_fd->inode->write);
diff --git a/kernel/network/arp.c b/kernel/network/arp.c
index dfa1131..b5825be 100644
--- a/kernel/network/arp.c
+++ b/kernel/network/arp.c
@@ -114,12 +114,6 @@ void handle_arp(const u8 *payload) {
assert(4 == data->plen);
// Assert it is a request
if (0x0001 /*arp_request*/ == ntohs(data->opcode)) {
- print_mac("srchw: ", data->srchw);
- print_ip("srcpr: ", data->srcpr);
-
- print_mac("dsthw: ", data->dsthw);
- print_ip("dstpr: ", data->dstpr);
-
struct ARP_TABLE_ENTRY *entry = find_arp_entry_to_use();
entry->is_used = 1;
memcpy(entry->mac, data->srchw, sizeof(uint8_t[6]));
@@ -148,7 +142,6 @@ void handle_arp(const u8 *payload) {
entry->is_used = 1;
memcpy(entry->mac, data->srchw, sizeof(u8[6]));
memcpy(entry->ip, data->srcpr, sizeof(u8[4]));
- print_ip("Added ip: ", entry->ip);
} else {
kprintf("GOT A ARP REQEUST WITH TYPE: %x\n", ntohs(data->opcode));
assert(0);
diff --git a/kernel/network/ethernet.c b/kernel/network/ethernet.c
index 5cf1a54..6255ecb 100644
--- a/kernel/network/ethernet.c
+++ b/kernel/network/ethernet.c
@@ -50,10 +50,6 @@ void handle_ethernet(const u8 *packet, u64 packet_length) {
packet += sizeof(struct ETHERNET_HEADER);
const u8 *payload = packet;
packet += packet_length - sizeof(struct ETHERNET_HEADER);
- u32 crc = *((u32 *)packet - 1);
- kprintf("PACKET crc: %x\n", crc);
- kprintf("OUR OWN CALCULATED crc: %x\n",
- crc32((const char *)eth_header, (packet_length - 4)));
u16 type = ntohs(eth_header->type);
switch (type) {
@@ -84,10 +80,8 @@ void send_ethernet_packet(u8 mac_dst[6], u16 type, u8 *payload,
memcpy(eth_header->mac_dst, mac_dst, sizeof(u8[6]));
get_mac_address(eth_header->mac_src);
eth_header->type = htons(type);
- *(u32 *)(buffer) =
- htonl(crc32((const char *)buffer_start, buffer_size - 4));
+ *(u32 *)(buffer) = htonl(crc32((const char *)buffer_start, buffer_size - 4));
assert(rtl8139_send_data(buffer_start, buffer_size));
kfree(buffer_start);
- kprintf("sent data\n");
}
diff --git a/kernel/network/ipv4.c b/kernel/network/ipv4.c
index 891e74f..e38ab9b 100644
--- a/kernel/network/ipv4.c
+++ b/kernel/network/ipv4.c
@@ -63,9 +63,7 @@ void send_ipv4_packet(u32 ip, u8 protocol, const u8 *payload,
memcpy(ip_copy, &ip, sizeof(u8[4]));
for (; !get_mac_from_ip(ip_copy, mac);)
;
- kprintf("pre send_ethernet: %x\n", pit_num_ms());
send_ethernet_packet(mac, 0x0800, packet, packet_length);
- kprintf("after send_ethernet: %x\n", pit_num_ms());
kfree(packet);
}
@@ -80,7 +78,6 @@ void handle_ipv4(const u8 *payload, u32 packet_length) {
u8 version = (*payload & 0xF0) >> 4;
u8 IHL = (*payload & 0xF);
- kprintf("version: %x\n", version);
assert(4 == version);
assert(5 == IHL);
u16 ipv4_total_length = ntohs(*(u16 *)(payload + 2));
diff --git a/kernel/network/tcp.c b/kernel/network/tcp.c
index 6c693cf..4b2c462 100644
--- a/kernel/network/tcp.c
+++ b/kernel/network/tcp.c
@@ -60,9 +60,8 @@ u16 tcp_checksum(u16 *buffer, int size) {
return (u16)(~cksum);
}
-void tcp_calculate_checksum(u8 src_ip[4], u8 dst_ip[4],
- const u8 *payload, u16 payload_length,
- struct TCP_HEADER *header) {
+void tcp_calculate_checksum(u8 src_ip[4], u8 dst_ip[4], const u8 *payload,
+ u16 payload_length, struct TCP_HEADER *header) {
struct PSEUDO_TCP_HEADER ps = {0};
memcpy(&ps.src_addr, src_ip, sizeof(u32));
memcpy(&ps.dst_addr, dst_ip, sizeof(u32));
@@ -135,8 +134,7 @@ void send_tcp_packet(struct INCOMING_TCP_CONNECTION *inc, u8 *payload,
}
void send_empty_tcp_message(struct INCOMING_TCP_CONNECTION *inc, u8 flags,
- u32 inc_seq_num, u16 n_dst_port,
- u16 n_src_port) {
+ u32 inc_seq_num, u16 n_dst_port, u16 n_src_port) {
struct TCP_HEADER header = {0};
header.src_port = n_dst_port;
header.dst_port = n_src_port;
@@ -148,15 +146,13 @@ void send_empty_tcp_message(struct INCOMING_TCP_CONNECTION *inc, u8 flags,
header.window_size = htons(512); // TODO: What does this actually mean?
header.urgent_pointer = 0;
char payload[0];
- tcp_calculate_checksum(ip_address, inc->ip, (const u8 *)payload, 0,
- &header);
+ tcp_calculate_checksum(ip_address, inc->ip, (const u8 *)payload, 0, &header);
u32 dst_ip;
memcpy(&dst_ip, inc->ip, sizeof(dst_ip));
send_ipv4_packet(dst_ip, 6, (const u8 *)&header, sizeof(header));
}
-void handle_tcp(u8 src_ip[4], const u8 *payload,
- u32 payload_length) {
+void handle_tcp(u8 src_ip[4], const u8 *payload, u32 payload_length) {
const struct TCP_HEADER *inc_header = (const struct TCP_HEADER *)payload;
u16 n_src_port = *(u16 *)(payload);
u16 n_dst_port = *(u16 *)(payload + 2);
@@ -225,12 +221,10 @@ void handle_tcp(u8 src_ip[4], const u8 *payload,
header.window_size = htons(512); // TODO: What does this actually mean?
header.urgent_pointer = 0;
char payload[0];
- tcp_calculate_checksum(ip_address, src_ip, (const u8 *)payload, 0,
- &header);
+ tcp_calculate_checksum(ip_address, src_ip, (const u8 *)payload, 0, &header);
u32 dst_ip;
memcpy(&dst_ip, src_ip, sizeof(dst_ip));
send_ipv4_packet(dst_ip, 6, (const u8 *)&header, sizeof(header));
- kprintf("after ipv4 packet: %x\n", pit_num_ms());
return;
}
}
diff --git a/kernel/socket.c b/kernel/socket.c
index 1922a93..630c203 100644
--- a/kernel/socket.c
+++ b/kernel/socket.c
@@ -14,8 +14,7 @@ OPEN_INET_SOCKET *inet_sockets[100] = {0};
struct INCOMING_TCP_CONNECTION tcp_connections[100] = {0};
-int tcp_socket_write(u8 *buffer, u64 offset, u64 len,
- vfs_fd_t *fd) {
+int tcp_socket_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
struct INCOMING_TCP_CONNECTION *s =
(struct INCOMING_TCP_CONNECTION *)fd->inode->internal_object;
if (s->connection_closed)
@@ -24,8 +23,7 @@ int tcp_socket_write(u8 *buffer, u64 offset, u64 len,
return len;
}
-int tcp_socket_read(u8 *buffer, u64 offset, u64 len,
- vfs_fd_t *fd) {
+int tcp_socket_read(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
struct INCOMING_TCP_CONNECTION *s =
(struct INCOMING_TCP_CONNECTION *)fd->inode->internal_object;
if (s->connection_closed)
@@ -60,8 +58,7 @@ struct INCOMING_TCP_CONNECTION *get_incoming_tcp_connection(u8 ip[4],
}
struct INCOMING_TCP_CONNECTION *
-handle_incoming_tcp_connection(u8 ip[4], u16 n_port,
- u16 dst_port) {
+handle_incoming_tcp_connection(u8 ip[4], u16 n_port, u16 dst_port) {
OPEN_INET_SOCKET *in = find_open_tcp_port(htons(dst_port));
if (!in) {
kprintf("TCP SYN to unopened port: %d\n", dst_port);
@@ -282,7 +279,7 @@ int socket(int domain, int type, int protocol) {
NULL /*truncate*/, NULL /*stat*/);
vfs_fd_t *fd;
- int n = vfs_create_fd(O_RDWR | O_NONBLOCK, 0, 0/*is_tty*/, inode, &fd);
+ int n = vfs_create_fd(O_RDWR | O_NONBLOCK, 0, 0 /*is_tty*/, inode, &fd);
new_socket->domain = domain;
new_socket->type = type;
diff --git a/kernel/socket.h b/kernel/socket.h
index 7be5571..5e8c3b1 100644
--- a/kernel/socket.h
+++ b/kernel/socket.h
@@ -85,8 +85,7 @@ int socket(int domain, int type, int protocol);
int accept(int socket, struct sockaddr *address, socklen_t *address_len);
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
struct INCOMING_TCP_CONNECTION *
-handle_incoming_tcp_connection(u8 ip[4], u16 n_port,
- u16 dst_port);
+handle_incoming_tcp_connection(u8 ip[4], u16 n_port, u16 dst_port);
struct INCOMING_TCP_CONNECTION *get_incoming_tcp_connection(u8 ip[4],
u16 n_port);
#endif
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;
+}