From 52461cacec49af96b6b0643f4322e9fc0b36d403 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 7 Nov 2015 17:58:55 +0000 Subject: 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. --- manpage.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'manpage.c') 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 * Copyright (c) 2013 Ingo Schwarze @@ -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++) -- cgit v1.2.3