diff options
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 |