diff options
author | Benji Dial <benji6283@gmail.com> | 2021-03-01 22:35:26 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-03-01 22:35:26 -0500 |
commit | 1d69a46f5d9823bbf2e6211ca367b409d2d5f7a7 (patch) | |
tree | a49a5498080551270a827a205cde49477d4d89ff /src/user/filetest/filetest.c | |
parent | 6f1b50a4cc6c232ee505a543f006abb1c6cd33cf (diff) | |
download | portland-os-1d69a46f5d9823bbf2e6211ca367b409d2d5f7a7.tar.gz |
minimal file writing, shutdown keybinding (Win+Shift+Q)
Diffstat (limited to 'src/user/filetest/filetest.c')
-rw-r--r-- | src/user/filetest/filetest.c | 36 |
1 files changed, 36 insertions, 0 deletions
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 <libterm/terminal.h> +#include <knob/file.h> + +#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 |