From e741336dd40440abd7ca9c6a74c04e1e2969770e Mon Sep 17 00:00:00 2001 From: naddy Date: Sun, 31 Jan 2021 14:24:47 +0000 Subject: [PATCH] replace fgetln(3) with getline(3) in fdisk ok millert@ --- sbin/fdisk/misc.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index d30db9bca72..759dfb3ae67 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.63 2019/07/03 03:24:01 deraadt Exp $ */ +/* $OpenBSD: misc.c,v 1.64 2021/01/31 14:24:47 naddy Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -64,20 +64,18 @@ unit_lookup(char *units) int string_from_line(char *buf, size_t buflen) { - char *line; - size_t sz; + static char *line; + static size_t sz; + ssize_t len; - line = fgetln(stdin, &sz); - if (line == NULL) + len = getline(&line, &sz, stdin); + if (len == -1) return (1); - if (line[sz - 1] == '\n') - sz--; - if (sz >= buflen) - sz = buflen - 1; + if (line[len - 1] == '\n') + line[len - 1] = '\0'; - memcpy(buf, line, sz); - buf[sz] = '\0'; + strlcpy(buf, line, buflen); return (0); } -- 2.20.1