summaryrefslogtreecommitdiff
path: root/src/user/filetest/filetest.c
blob: af01e1cbd90a71d2108da2083e9b308d32523237 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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);
}