aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/stdin.c
blob: 556c7cff18eb4726ec279b61f00d3ebe8baeee26 (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
26
27
28
/*
 * blogc: A blog compiler.
 * Copyright (C) 2014-2020 Rafael G. Martins <rafael@rafaelmartins.eng.br>
 *
 * This program can be distributed under the terms of the BSD License.
 * See the file LICENSE.
 */

#include <stdbool.h>
#include <stdio.h>
#include "utils.h"
#include "stdin.h"


// splitted in single file to make it easier to test
char*
bc_stdin_read(size_t *len)
{
    if (len == NULL)
        return NULL;

    int c;
    bc_string_t *rv = bc_string_new();
    while (EOF != (c = fgetc(stdin)))
        bc_string_append_c(rv, c);
    *len = rv->len;
    return bc_string_free(rv, false);
}