From 1d69a46f5d9823bbf2e6211ca367b409d2d5f7a7 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 1 Mar 2021 22:35:26 -0500 Subject: minimal file writing, shutdown keybinding (Win+Shift+Q) --- src/user/filetest/filetest.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/user/filetest/filetest.c (limited to 'src/user/filetest') diff --git a/src/user/filetest/filetest.c b/src/user/filetest/filetest.c new file mode 100644 index 0000000..e7792ff --- /dev/null +++ b/src/user/filetest/filetest.c @@ -0,0 +1,36 @@ +#include +#include + +#define TEST_FILE "user/test.txt" + +void main() { + struct file *f = open_file(TEST_FILE); + if (!f) { + term_add_sz("Failed to open " TEST_FILE ".\n"); + return; + } + + char ch; + if (!read_from_file(f, 1, &ch)) { + term_add_sz(TEST_FILE " is empty.\n"); + close_file(f); + return; + } + + term_addf(TEST_FILE " contained '%c'.\n", ch); + + if (++ch >= 0x7f) + ch = 0x21; + + seek_file_to(f, 0); + + if (!write_to_file(f, 1, &ch)) { + term_add_sz("Failed to write to " TEST_FILE ".\n"); + close_file(f); + return; + } + + term_addf("Wrote '%c' to " TEST_FILE ".\n", ch); + + close_file(f); +} \ No newline at end of file -- cgit v1.2.3