From: naddy Date: Tue, 2 Feb 2021 15:42:00 +0000 (+0000) Subject: replace fgetln(3) with getline(3) in disklabel X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=58c7d7ac79dfd59b623e4857c310b266cc721e5e;p=openbsd replace fgetln(3) with getline(3) in disklabel Since getline() returns a C string, we don't need to carry around the length separately. ok millert@ --- diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index feab5969e5d..07e8250cef4 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.364 2021/01/31 14:18:44 naddy Exp $ */ +/* $OpenBSD: editor.c,v 1.365 2021/02/02 15:42:00 naddy Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller @@ -172,7 +172,7 @@ void zero_partitions(struct disklabel *); u_int64_t max_partition_size(struct disklabel *, int); void display_edit(struct disklabel *, char); void psize(u_int64_t sz, char unit, struct disklabel *lp); -char *get_token(char **, size_t *); +char *get_token(char **); int apply_unit(double, u_char, u_int64_t *); int parse_sizespec(const char *, double *, char **); int parse_sizerange(char *, u_int64_t *, u_int64_t *); @@ -2331,8 +2331,8 @@ void parse_autotable(char *filename) { FILE *cfile; - size_t len; - char *buf, *t; + size_t bufsize = 0; + char *buf = NULL, *t; uint idx = 0, pctsum = 0; struct space_allocation *sa; @@ -2342,7 +2342,7 @@ parse_autotable(char *filename) err(1, NULL); alloc_table_nitems = 1; - while ((buf = fgetln(cfile, &len)) != NULL) { + while (getline(&buf, &bufsize, cfile) != -1) { if ((alloc_table[0].table = reallocarray(alloc_table[0].table, idx + 1, sizeof(*sa))) == NULL) err(1, NULL); @@ -2350,13 +2350,13 @@ parse_autotable(char *filename) memset(sa, 0, sizeof(*sa)); idx++; - if ((sa->mp = get_token(&buf, &len)) == NULL || + if ((sa->mp = get_token(&buf)) == NULL || (sa->mp[0] != '/' && strcmp(sa->mp, "swap"))) errx(1, "%s: parse error on line %u", filename, idx); - if ((t = get_token(&buf, &len)) == NULL || + if ((t = get_token(&buf)) == NULL || parse_sizerange(t, &sa->minsz, &sa->maxsz) == -1) errx(1, "%s: parse error on line %u", filename, idx); - if ((t = get_token(&buf, &len)) != NULL && + if ((t = get_token(&buf)) != NULL && parse_pct(t, &sa->rate) == -1) errx(1, "%s: parse error on line %u", filename, idx); if (sa->minsz > sa->maxsz) @@ -2367,29 +2367,27 @@ parse_autotable(char *filename) if (pctsum > 100) errx(1, "%s: sum of extra space allocation > 100%%", filename); alloc_table[0].sz = idx; + free(buf); fclose(cfile); } char * -get_token(char **s, size_t *len) +get_token(char **s) { char *p, *r; size_t tlen = 0; p = *s; - while (*len > 0 && !isspace((u_char)**s)) { + while (**s != '\0' && !isspace((u_char)**s)) { (*s)++; - (*len)--; tlen++; } if (tlen == 0) return (NULL); /* eat whitespace */ - while (*len > 0 && isspace((u_char)**s)) { + while (isspace((u_char)**s)) (*s)++; - (*len)--; - } if ((r = strndup(p, tlen)) == NULL) err(1, NULL);