summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-06-27 18:59:49 +0200
committerAnton Kling <anton@kling.gg>2024-06-27 19:07:50 +0200
commitd315a82dbed1fd288702ebbcb869c744476433a8 (patch)
treeb58ec3831daa0abf0dd2dd5dd4395e53565bd1c7 /userland
parent556d1e44fef369a7200cc045f337ac3db2f9eab5 (diff)
stuff
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/Makefile2
-rw-r--r--userland/libc/include/stdio.h1
-rw-r--r--userland/libc/include/syscall.h3
-rw-r--r--userland/libc/include/time.h1
-rw-r--r--userland/libc/libc.c6
-rw-r--r--userland/libgui/Makefile4
-rw-r--r--userland/libgui/libgui.c48
-rw-r--r--userland/libgui/libgui.h13
-rw-r--r--userland/libppm/ppm.c28
-rw-r--r--userland/terminal/term.c7
-rwxr-xr-xuserland/test/linux.sh4
-rw-r--r--userland/test/test.c69
12 files changed, 153 insertions, 33 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile
index 8db5a16..936bde6 100644
--- a/userland/libc/Makefile
+++ b/userland/libc/Makefile
@@ -2,7 +2,7 @@ CC="i686-sb-gcc"
AR="i686-sb-ar"
AS="i686-sb-as"
CFLAGS = -ggdb -ffreestanding -nostdlib -O0 -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 unistd/lseek.o ctype/isupper.o ctype/islower.o ctype/isblank.o ctype/isgraph.o ctype/iscntrl.o math/ldexp.o sys/socket/connect.o sys/socket/setsockopt.o arpa/inet/ntohl.o arpa/inet/ntohs.o netdb/getaddrinfo.o tb/sha1.o sys/socket/getpeername.o
+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 unistd/lseek.o ctype/isupper.o ctype/islower.o ctype/isblank.o ctype/isgraph.o ctype/iscntrl.o math/ldexp.o sys/socket/connect.o sys/socket/setsockopt.o arpa/inet/ntohl.o arpa/inet/ntohs.o netdb/getaddrinfo.o tb/sha1.o sys/socket/getpeername.o fcntl/fcntl.o
all: libc.a
%.o: %.c
diff --git a/userland/libc/include/stdio.h b/userland/libc/include/stdio.h
index b0bfbd1..aebf086 100644
--- a/userland/libc/include/stdio.h
+++ b/userland/libc/include/stdio.h
@@ -68,7 +68,6 @@ int puts(const char *s);
int brk(void *addr);
void *sbrk(intptr_t increment);
int printf(const char *format, ...);
-int mread(int fd, void *buf, size_t count, int blocking);
int pread(int fd, void *buf, size_t count, size_t offset);
int read(int fd, void *buf, size_t count);
int fork(void);
diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h
index fee2e43..e1c0b07 100644
--- a/userland/libc/include/syscall.h
+++ b/userland/libc/include/syscall.h
@@ -6,7 +6,7 @@
#include <sys/types.h>
#define SYS_OPEN 0
-#define SYS_MREAD 1
+#define SYS_READ 1
#define SYS_WRITE 2
#define SYS_PREAD 3
#define SYS_PWRITE 4
@@ -46,6 +46,7 @@
#define SYS_CONNECT 38
#define SYS_SETSOCKOPT 39
#define SYS_GETPEERNAME 40
+#define SYS_FCNTL 41
int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx,
uint32_t esi, uint32_t edi);
diff --git a/userland/libc/include/time.h b/userland/libc/include/time.h
index 567e9ef..b494f6c 100644
--- a/userland/libc/include/time.h
+++ b/userland/libc/include/time.h
@@ -4,6 +4,7 @@
#include <stddef.h>
#define CLOCK_REALTIME 0
+#define CLOCK_MONOTONIC_RAW 1
struct tm {
int tm_sec;
diff --git a/userland/libc/libc.c b/userland/libc/libc.c
index 8129448..31d8648 100644
--- a/userland/libc/libc.c
+++ b/userland/libc/libc.c
@@ -203,12 +203,8 @@ int pread(int fd, void *buf, size_t count, size_t offset) {
RC_ERRNO(syscall(SYS_PREAD, (u32)&args, 0, 0, 0, 0));
}
-int mread(int fd, void *buf, size_t count, int blocking) {
- RC_ERRNO(syscall(SYS_MREAD, fd, buf, count, blocking, 0));
-}
-
int read(int fd, void *buf, size_t count) {
- return mread(fd, buf, count, 1);
+ RC_ERRNO(syscall(SYS_READ, fd, buf, count, 0, 0));
}
int dup2(int org_fd, int new_fd) {
diff --git a/userland/libgui/Makefile b/userland/libgui/Makefile
index 584fda6..bdd7530 100644
--- a/userland/libgui/Makefile
+++ b/userland/libgui/Makefile
@@ -12,5 +12,9 @@ libgui.o: libgui.c
libgui.a: $(OBJ)
$(AR) rcs libgui.a $^
+install:
+ mkdir -p ../../sysroot/usr/include
+ cp libgui.h ../../sysroot/usr/include/
+
clean:
rm $(OBJ) $(BINS)
diff --git a/userland/libgui/libgui.c b/userland/libgui/libgui.c
index 07edbdd..458ab07 100644
--- a/userland/libgui/libgui.c
+++ b/userland/libgui/libgui.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
+#include <typedefs.h>
#include <unistd.h>
#define place_pixel_pos(_p, _pos) \
@@ -191,6 +192,27 @@ void GUI_OverwriteFont(GUI_Window *w, uint32_t px, uint32_t py,
}
}
+void GUI_DrawLine(GUI_Window *w, uint32_t sx, uint32_t sy, uint32_t dx,
+ uint32_t dy, uint32_t rgba) {
+ for (;;) {
+ // Bounds checking
+ if (sy * w->sx + sx > w->sy * w->sx)
+ break;
+
+ if (sx >= dx - 1 && sy >= dy - 1) {
+ break;
+ }
+ uint32_t *ptr = w->bitmap_ptr + (sy * w->sx) + sx;
+ *ptr = rgba;
+ if (sx < dx - 1) {
+ sx++;
+ }
+ if (sy < dy - 1) {
+ sy++;
+ }
+ }
+}
+
void GUI_DrawFont(GUI_Window *w, uint32_t px, uint32_t py, const uint32_t c) {
int sx, sy;
sx = 8;
@@ -260,13 +282,20 @@ void GUI_EventLoop(GUI_Window *w, void (*event_handler)(WS_EVENT ev)) {
// window can be given a sufficently large buffer such that buffers
// don't have to be resized if the window is resized.
#define MAX_WINDOW_SIZE (1920 * 1080)
-void GUI_Resize(GUI_Window *w, uint32_t sx, uint32_t sy) {
+int GUI_BufferResize(GUI_Window *w, uint32_t sx, uint32_t sy) {
if (sx * sy > MAX_WINDOW_SIZE) {
- return;
+ return 0;
}
-
w->sx = sx;
w->sy = sy;
+ return 1;
+}
+
+int GUI_SendResize(GUI_Window *w, uint32_t sx, uint32_t sy) {
+ if (!GUI_BufferResize(w, sx, sy)) {
+ return 0;
+ }
+
char buffer[sizeof(uint8_t) + sizeof(uint32_t) * 2];
uint8_t l = 2;
memcpy(buffer, &l, sizeof(l));
@@ -274,6 +303,19 @@ void GUI_Resize(GUI_Window *w, uint32_t sx, uint32_t sy) {
memcpy(buffer + sizeof(uint8_t) + sizeof(uint32_t), &sy, sizeof(sy));
int len = sizeof(uint8_t) + sizeof(uint32_t) * 2;
write(w->ws_socket, buffer, len);
+ return 1;
+}
+
+void GUI_DrawRectangle(GUI_Window *w, uint32_t x, uint32_t y, uint32_t sx,
+ uint32_t sy, uint32_t color) {
+ for (u32 l = y; l < y + sy; l++) {
+ for (u32 s = x; s < x + sx; s++) {
+ if(l*w->sx + s > w->sx*w->sy) {
+ break;
+ }
+ w->bitmap_ptr[l * w->sx + s] = color;
+ }
+ }
}
GUI_Window *GUI_CreateWindow(uint32_t x, uint32_t y, uint32_t sx, uint32_t sy) {
diff --git a/userland/libgui/libgui.h b/userland/libgui/libgui.h
index 1c3ac95..85e1dda 100644
--- a/userland/libgui/libgui.h
+++ b/userland/libgui/libgui.h
@@ -7,6 +7,10 @@
#define WINDOWSERVER_EVENT_WINDOW_EXIT 1
#define WINDOWSERVER_EVENT_WINDOW_RESIZE 2
+#define EV_SHIFT(_mode) ((_mode) & (1 << 0))
+#define EV_ALT(_mode) ((_mode) & (1 << 1))
+#define EV_CTRL(_mode) ((_mode) & (1 << 2))
+
typedef struct {
int ws_socket;
int bitmap_fd;
@@ -38,6 +42,13 @@ void GUI_UpdateWindow(GUI_Window *w);
void GUI_OverwriteFont(GUI_Window *w, uint32_t px, uint32_t py,
const uint32_t color);
void GUI_ClearScreen(GUI_Window *w, uint32_t color);
+void GUI_DrawRectangle(GUI_Window *w, uint32_t x, uint32_t y, uint32_t sx,
+ uint32_t sy, uint32_t color);
void GUI_EventLoop(GUI_Window *w, void (*event_handler)(WS_EVENT ev));
-void GUI_Resize(GUI_Window *w, uint32_t sx, uint32_t sy);
+int GUI_BufferResize(GUI_Window *w, uint32_t sx, uint32_t sy);
+int GUI_SendResize(GUI_Window *w, uint32_t sx, uint32_t sy);
+void GUI_DrawLine(GUI_Window *w, uint32_t sx, uint32_t sy, uint32_t dx,
+ uint32_t dy, uint32_t rgba);
+void GUI_DrawRectangle(GUI_Window *w, uint32_t x, uint32_t y, uint32_t sx,
+ uint32_t sy, uint32_t color);
#endif
diff --git a/userland/libppm/ppm.c b/userland/libppm/ppm.c
index 9013e27..ec70a6d 100644
--- a/userland/libppm/ppm.c
+++ b/userland/libppm/ppm.c
@@ -27,13 +27,19 @@ int parse_ppm_header(FILE *fp, struct PPM_IMAGE *img) {
char c1;
char c2;
fscanf(fp, "%c%c\n%d %d\n%d", &c1, &c2, &width, &height, &maxval);
- if ('P' != c1)
+ if ('P' != c1) {
+ printf("c1: %c\n", c1);
return 0;
- if (!isdigit(c2))
+ }
+ if (!isdigit(c2)) {
+ printf("c2: %c\n", c2);
return 0;
+ }
img->version = c2 - '0';
- if (3 != img->version && 6 != img->version)
+ if (3 != img->version && 6 != img->version) {
+ printf("Not handeld version\n");
return 0;
+ }
if (maxval > 255) {
printf("maxval is: %d\n", maxval);
return 0;
@@ -42,8 +48,7 @@ int parse_ppm_header(FILE *fp, struct PPM_IMAGE *img) {
img->height = height;
img->maxval = maxval;
img->file_location = ftell(fp);
- printf("width: %d\n", img->width);
- printf("height: %d\n", img->height);
+ img->file_location++;
return 1;
}
@@ -59,26 +64,25 @@ int load_ppm6_file(FILE *fp, const struct PPM_IMAGE *img, uint32_t buf_width,
int cx = 0;
int cy = 0;
const int n_pixels = img->width * img->height;
- printf("malloc\n");
uint8_t *rgb = malloc(3 * n_pixels);
- printf("end malloc\n");
- printf("fread");
const int rc = fread(rgb, 3, n_pixels, fp);
if (0 == rc)
return 0;
- printf("end fread");
uint32_t *p = rgb;
u32 buf_size = buf_height * buf_width;
if (1 == modifier) {
- for (int i = 0; i < rc && i < buf_size; i++, p = ((uint8_t *)p) + 3) {
+ int c = 0;
+ for (int i = 0; i < rc && i < buf_size; i++, c += 3) {
if (cx > buf_width) {
i--;
} else {
- uint32_t v = *p;
+ u8 red = rgb[c];
+ u8 green = rgb[c + 1];
+ u8 blue = rgb[c + 2];
buffer[cy * buf_width + cx] =
- ((v & 0xFF) << 16) | ((v & 0xFF00)) | ((v & 0xFF0000) >> 16);
+ (red << (8 * 2)) | (green << (8 * 1)) | (blue << (8 * 0));
}
cx++;
if (cx == img->width) {
diff --git a/userland/terminal/term.c b/userland/terminal/term.c
index ced3a60..246474f 100644
--- a/userland/terminal/term.c
+++ b/userland/terminal/term.c
@@ -228,12 +228,15 @@ void handle_escape_codes_or_print(char *buffer, int len) {
}
void terminal_resize(uint32_t sx, uint32_t sy) {
- GUI_Resize(global_w, sx, sy);
+ assert(GUI_BufferResize(global_w, sx, sy));
for (int y = 0; y < sy; y += 8) {
- for (int x = 0; x < sx; x += 8) {
+ int x = 0;
+ for (; x < sx; x += 8) {
GUI_DrawFont(global_w, x, y, terminal_char_buffer[y / 8][x / 8]);
}
+ GUI_DrawLine(global_w, x, y, sx, y, 0xFF00FF);
}
+ assert(GUI_SendResize(global_w, sx, sy));
}
void run() {
diff --git a/userland/test/linux.sh b/userland/test/linux.sh
index d40d6cc..1cb1668 100755
--- a/userland/test/linux.sh
+++ b/userland/test/linux.sh
@@ -1,4 +1,4 @@
#!/bin/bash
-gcc -DLINUX test.c -o ./local/a.out
+gcc -DLINUX test.c -g -o ./local/a.out || exit
cd local
-./a.out
+valgrind ./a.out
diff --git a/userland/test/test.c b/userland/test/test.c
index 33361a5..1bebee7 100644
--- a/userland/test/test.c
+++ b/userland/test/test.c
@@ -1,13 +1,14 @@
#include <assert.h>
#include <fcntl.h>
-//#include <json.h>
#include <ctype.h>
#include <errno.h>
+#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <tb/sha1.h>
#if 1
void dbgln(const char *fmt) {
@@ -53,7 +54,6 @@ void isx_test() {
void malloc_test(void) {
dbgln("malloc TEST");
for (int j = 0; j < 100; j++) {
- // printf("j : %x\n", j);
uint8_t *t = malloc(400 + j);
memset(t, 0x43 + (j % 10), 400 + j);
uint8_t *p = malloc(900 + j);
@@ -269,6 +269,7 @@ void strncpy_test(void) {
dbgln("strncpy TEST PASSED");
}
+#ifndef linux
void strlcpy_test(void) {
dbgln("strlcpy TEST");
{
@@ -279,6 +280,7 @@ void strlcpy_test(void) {
}
dbgln("strlcpy TEST PASSED");
}
+#endif
void strcat_test(void) {
dbgln("strcat TEST");
@@ -429,7 +431,7 @@ void strcasecmp_test(void) {
{
assert(0 == strcasecmp("foobar", "FOObar"));
assert(0 == strcasecmp("foobar", "foobar"));
- assert(6 == strcasecmp("foobar", "bar"));
+ assert(0 < strcasecmp("foobar", "bar"));
}
dbgln("strcasecmp TEST PASSED");
}
@@ -458,12 +460,14 @@ void strstr_test(void) {
void strtok_test(void) {
dbgln("strtok TEST");
{
- char *s = "hello,world,goodbye";
+ char s[4096];
+ strcpy(s, "hello,world,goodbye");
assert(0 == strcmp(strtok(s, ","), "hello"));
assert(0 == strcmp(strtok(NULL, ","), "world"));
assert(0 == strcmp(strtok(NULL, ","), "goodbye"));
assert(NULL == strtok(NULL, ","));
- char *s2 = "hello,,world,,goodbye,test";
+ char s2[4096];
+ strcpy(s2, "hello,,world,,goodbye,test");
assert(0 == strcmp(strtok(s2, ",,"), "hello"));
assert(0 == strcmp(strtok(NULL, ",,"), "world"));
assert(0 == strcmp(strtok(NULL, ","), "goodbye"));
@@ -660,6 +664,7 @@ void qsort_test(void) {
dbgln("qsort TEST PASSED");
}
+#ifndef linux
void basename_test(void) {
dbgln("basename TEST");
{
@@ -690,7 +695,9 @@ void basename_test(void) {
}
dbgln("basename TEST PASSED");
}
+#endif
+#ifndef linux
void dirname_test(void) {
dbgln("dirname TEST");
{
@@ -710,6 +717,7 @@ void dirname_test(void) {
}
dbgln("dirname TEST PASSED");
}
+#endif
void getline_test(void) {
dbgln("getline TEST");
@@ -773,6 +781,7 @@ void memchr_test(void) {
dbgln("memchr TEST PASSED");
}
+#ifndef linux
void randomfill_test(void) {
dbgln("randomfill TEST");
{
@@ -792,6 +801,49 @@ void randomfill_test(void) {
}
dbgln("randomfill TEST PASSED");
}
+#endif
+
+void fs_test() {
+ dbgln("filesystem TEST");
+ {
+ u8 file_digest[SHA1_LEN];
+ u8 direct_digest[SHA1_LEN];
+ SHA1_CTX ctx;
+ char buffer[4096];
+ {
+ SHA1_Init(&ctx);
+ int fd = open("hashfile", O_RDWR | O_CREAT);
+ assert(-1 != fd);
+
+ memset(buffer, 'A', 4096);
+
+ for (int i = 0; i < 2; i++) {
+ write(fd, buffer, 4096);
+ }
+
+ memset(buffer, 0, 4096);
+ lseek(fd, 0, SEEK_SET);
+
+ for (int i = 0; i < 2; i++) {
+ int rc = read(fd, buffer, 4096);
+ assert(4096 == rc);
+ SHA1_Update(&ctx, buffer, 4096);
+ }
+ SHA1_Final(&ctx, file_digest);
+ close(fd);
+ }
+ {
+ SHA1_Init(&ctx);
+ memset(buffer, 'A', 4096);
+ for (int i = 0; i < 2; i++) {
+ SHA1_Update(&ctx, buffer, 4096);
+ }
+ SHA1_Final(&ctx, direct_digest);
+ }
+ assert(0 == memcmp(file_digest, direct_digest, SHA1_LEN));
+ }
+ dbgln("filesystem TEST PASSED");
+}
int main(void) {
dbgln("START");
@@ -810,7 +862,9 @@ int main(void) {
strpbrk_test();
strcpy_test();
strncpy_test();
+#ifndef linux
strlcpy_test();
+#endif
strcat_test();
strchr_test();
strrchr_test();
@@ -829,12 +883,17 @@ int main(void) {
// fseek_test();
printf_test();
qsort_test();
+#ifndef linux
basename_test();
dirname_test();
+#endif
getline_test();
realpath_test();
memchr_test();
+ fs_test();
+#ifndef linux
randomfill_test();
+#endif
// TODO: Add mkstemp
return 0;
}