]> diplodocus.org Git - nmh/blob - sbr/read_line.c
Fix invalid pointer arithmetic.
[nmh] / sbr / read_line.c
1 /* read_line.c -- read a possibly incomplete line from stdin.
2 *
3 * This code is Copyright (c) 2017, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9 #include <h/utils.h>
10 #include "read_line.h"
11
12 /*
13 * Flush standard output, read a line from standard input into a static buffer,
14 * zero out the newline, and return a pointer to the buffer.
15 * On error, return NULL.
16 */
17 const char *
18 read_line(void)
19 {
20 static char line[BUFSIZ];
21
22 fflush(stdout);
23 if (fgets(line, sizeof(line), stdin) == NULL)
24 return NULL;
25 trim_suffix_c(line, '\n');
26
27 return line; /* May not be a complete line. */
28 }