summaryrefslogtreecommitdiff
path: root/sbin/fdisk
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@cvs.openbsd.org>2021-01-31 14:24:48 +0000
committerChristian Weisgerber <naddy@cvs.openbsd.org>2021-01-31 14:24:48 +0000
commite0eea43cb1d95297e744994b3852030c08ec1cee (patch)
treeee48a735d0763a75f2dbe5f175bd25c509d51cf9 /sbin/fdisk
parentbe2f6623eb37f438bc07b3a438bd79e1083818ea (diff)
replace fgetln(3) with getline(3) in fdisk
ok millert@
Diffstat (limited to 'sbin/fdisk')
-rw-r--r--sbin/fdisk/misc.c20
1 files 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);
}