summaryrefslogtreecommitdiff
path: root/src/user/libcanyo/file.c
blob: d3148873b9a89c1801724c386f220247bb56143b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdint.h>
#include <pland.h>

//max_length and return value include null-terminator
uint32_t read_line(fs_handle handle, uint32_t max_length, void *buffer) {
  int index = 0;

  while (++index < max_length) {
    if (!fs_read(handle, 1, buffer + index - 1) || (*(uint8_t *)(buffer + index - 1) == '\n'))
      break;
  }

  *(uint8_t *)(buffer + index - 1) = '\0';
  return index;
}