summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2021-09-09 12:36:46 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2021-09-09 12:36:46 +0000
commit22f8abcc99b14c8b3b842672126d878d7202e20f (patch)
treeb8a3a0c3d29507b7f9901145cd7d851a18583760 /sbin
parentf7934f3a201930a65fa6775d4f929304f08abcc7 (diff)
Scan unit_types[] array using nitems() and eliminate the NULL
sentinal entry. No functional change.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/fdisk/misc.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c
index ce349826f53..5ffed50c542 100644
--- a/sbin/fdisk/misc.c
+++ b/sbin/fdisk/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.82 2021/08/28 11:55:17 krw Exp $ */
+/* $OpenBSD: misc.c,v 1.83 2021/09/09 12:36:45 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -37,26 +37,21 @@ struct unit_type unit_types[] = {
{ "M" , 1024LL * 1024 , "Megabytes" },
{ "G" , 1024LL * 1024 *1024 , "Gigabytes" },
{ "T" , 1024LL * 1024 * 1024 * 1024 , "Terabytes" },
- { NULL , 0 , NULL },
};
int
unit_lookup(const char *units)
{
- int i = 0;
+ unsigned int i;
- if (units == NULL)
- return SECTORS;
-
- while (unit_types[i].ut_abbr != NULL) {
- if (strncasecmp(unit_types[i].ut_abbr, units, 1) == 0)
- break;
- i++;
+ if (units != NULL) {
+ for (i = 0; i < nitems(unit_types); i++) {
+ if (strncasecmp(unit_types[i].ut_abbr, units, 1) == 0)
+ return i;
+ }
}
- if (unit_types[i].ut_abbr == NULL)
- return SECTORS;
- return i;
+ return SECTORS;
}
void