summaryrefslogtreecommitdiffstats
path: root/manpage.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-11-07 17:58:55 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-11-07 17:58:55 +0000
commitf024d444d299de331f8a9c932e479fedfbba6c5e (patch)
tree475615c6cfec51ea70542f32984d50357bc9459c /manpage.c
parent0441e71e8746df106efe8cf9b9ecb18f0d0824a4 (diff)
downloadmandoc-f024d444d299de331f8a9c932e479fedfbba6c5e.tar.gz
Modernization, no functional change intended:
Use the POSIX function getline(3) rather than the slightly dangerous BSD function fgetln(3). Remove the related compatibility code.
Diffstat (limited to 'manpage.c')
-rw-r--r--manpage.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/manpage.c b/manpage.c
index 27dedc8e..d33465f7 100644
--- a/manpage.c
+++ b/manpage.c
@@ -37,10 +37,11 @@ int
main(int argc, char *argv[])
{
int ch, term;
- size_t i, sz, len;
+ size_t i, sz, linesz;
+ ssize_t len;
struct mansearch search;
struct manpage *res;
- char *conf_file, *defpaths, *auxpaths, *cp;
+ char *conf_file, *defpaths, *auxpaths, *line;
char buf[PATH_MAX];
const char *cmd;
struct manconf conf;
@@ -124,12 +125,16 @@ main(int argc, char *argv[])
printf("Enter a choice [1]: ");
fflush(stdout);
- if (NULL != (cp = fgetln(stdin, &len)))
- if ('\n' == cp[--len] && len > 0) {
- cp[len] = '\0';
- if ((i = atoi(cp)) < 1 || i > sz)
+ line = NULL;
+ linesz = 0;
+ if ((len = getline(&line, &linesz, stdin)) != -1) {
+ if ('\n' == line[--len] && len > 0) {
+ line[len] = '\0';
+ if ((i = atoi(line)) < 1 || i > sz)
i = 0;
}
+ }
+ free(line);
if (0 == i) {
for (i = 0; i < sz; i++)