summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-07-26 17:03:06 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-07-26 17:03:06 +0000
commit2e65fdd1f9d9feef62e859371980b09572f7ff93 (patch)
tree506c09f33ec515e66ba734b770a6d8e195cb4066 /sbin
parente50c9dab7c20ef330d7a08c608e433e459a0fcc3 (diff)
use calloc() instead of malloc(); zinovik@cs.karelia.ru
Diffstat (limited to 'sbin')
-rw-r--r--sbin/swapctl/swaplist.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/sbin/swapctl/swaplist.c b/sbin/swapctl/swaplist.c
index 4aab6e7ed2b..2cca12df0f7 100644
--- a/sbin/swapctl/swaplist.c
+++ b/sbin/swapctl/swaplist.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: swaplist.c,v 1.6 2007/07/16 21:05:46 millert Exp $ */
+/* $OpenBSD: swaplist.c,v 1.7 2007/07/26 17:03:05 deraadt Exp $ */
/* $NetBSD: swaplist.c,v 1.8 1998/10/08 10:00:31 mrg Exp $ */
/*
@@ -51,16 +51,15 @@ list_swap(int pri, int kflag, int pflag, int dolong)
char *header;
size_t l;
int hlen, totalsize, size, totalinuse, inuse, ncounted, pathmax;
- int rnswap, nswap = swapctl(SWAP_NSWAP, 0, 0), i;
+ int rnswap, nswap, i;
- if (nswap < 1) {
- puts("no swap devices configured");
- exit(0);
- }
+ nswap = swapctl(SWAP_NSWAP, 0, 0);
+ if (nswap < 1)
+ errx(1, "no swap devices configured");
- fsep = sep = (struct swapent *)malloc(nswap * sizeof(*sep));
+ fsep = sep = (struct swapent *)calloc(nswap, sizeof(*sep));
if (sep == NULL)
- err(1, "malloc");
+ err(1, "calloc");
rnswap = swapctl(SWAP_STATS, (void *)sep, nswap);
if (rnswap < 0)
err(1, "SWAP_STATS");
@@ -106,8 +105,8 @@ list_swap(int pri, int kflag, int pflag, int dolong)
}
}
if (dolong == 0)
- printf("total: %ldk bytes allocated = %ldk used, "
- "%ldk available\n",
+ printf("total: %ldk bytes allocated = %ldk used, "
+ "%ldk available\n",
(long)(dbtoqb(totalsize) / 1024),
(long)(dbtoqb(totalinuse) / 1024),
(long)(dbtoqb(totalsize - totalinuse) / 1024));
@@ -119,5 +118,5 @@ list_swap(int pri, int kflag, int pflag, int dolong)
(long)(dbtoqb(totalsize - totalinuse) / blocksize),
(double)(totalinuse) / (double)totalsize * 100.0);
if (fsep)
- (void)free(fsep);
+ free(fsep);
}