summaryrefslogtreecommitdiff
path: root/src/io/lines.h
blob: b09b756b20ac7c5f9c5d78373c3906adafbd4d73 (plain)
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
#pragma once

#include <stdio.h>
#include <stdbool.h>

#include "util/string_view.h"


struct file_lines {
  const char *progname, *fname;

  FILE *f;
  size_t cap;
  char *buffer;
  size_t cursor;
  size_t readfrom;  // if -1, no newline in buffer
};

// Returns false on EOF. FILE remains ownership of the caller.
bool file_lines_open(const char *progname, const char *fname, FILE *f, struct file_lines *dst);

// Returns whether successful
bool file_lines_read(struct file_lines *fl, struct string_view *dst);

void file_lines_close(struct file_lines *fl);