aboutsummaryrefslogtreecommitdiffstatshomepage
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
commit52461cacec49af96b6b0643f4322e9fc0b36d403 (patch)
treeaaf6acf44516521f4f6604b822aecfff87e96d54 /manpage.c
parentb897019f5696c540f454bcb428d44ad31ef65559 (diff)
downloadmandoc-52461cacec49af96b6b0643f4322e9fc0b36d403.tar.gz
mandoc-52461cacec49af96b6b0643f4322e9fc0b36d403.tar.zst
mandoc-52461cacec49af96b6b0643f4322e9fc0b36d403.zip
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.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/manpage.c b/manpage.c
index 882917b5..45b6e765 100644
--- a/manpage.c
+++ b/manpage.c
@@ -1,4 +1,4 @@
-/* $Id: manpage.c,v 1.12 2015/10/06 18:32:19 schwarze Exp $ */
+/* $Id: manpage.c,v 1.13 2015/11/07 17:58:55 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -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++)