summaryrefslogtreecommitdiff
path: root/src/user/init/main.c
blob: 9a411e7e9374e0430eefebd4743bb52607e67f4d (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
#include <knob/user.h>
#include <knob/file.h>
#include <knob/heap.h>

void main() {
  tell_user_sz("\n\nThis is a userland program.\n");

  tell_user_sz("Opening sd0:TEST.TXT.\n");
  struct file *f = open_file("sd0:TEST.TXT");
  if (!f) {
    tell_user_sz("Failed to open.\n");
    return;
  }

  tell_user_sz("Length: ");
  uint32_t size = file_size(f);
  tell_user_n(size);
  tell_user_sz(" bytes\n\nContents:\n");

  char *buf = get_block(size + 1);
  read_from_file(f, size, buf);
  buf[size] = '\0';

  close_file(f);

  tell_user_sz(buf);

  tell_user_sz("\n\nGoodbye!\n");
}