Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/systat Avoid string gymnastics in an olympic year.
details: https://anonhg.NetBSD.org/src/rev/feb368840c7f
branches: trunk
changeset: 346850:feb368840c7f
user: christos <christos%NetBSD.org@localhost>
date: Fri Aug 05 07:22:17 2016 +0000
description:
Avoid string gymnastics in an olympic year.
diffstat:
usr.bin/systat/ifstat.c | 21 ++++-----------------
1 files changed, 4 insertions(+), 17 deletions(-)
diffs (45 lines):
diff -r 1a52f8518335 -r feb368840c7f usr.bin/systat/ifstat.c
--- a/usr.bin/systat/ifstat.c Fri Aug 05 06:58:55 2016 +0000
+++ b/usr.bin/systat/ifstat.c Fri Aug 05 07:22:17 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ifstat.c,v 1.3 2016/08/04 12:56:31 jakllsch Exp $ */
+/* $NetBSD: ifstat.c,v 1.4 2016/08/05 07:22:17 christos Exp $ */
/*
* Copyright (c) 2003, Trent Nelson, <trent%arpa.com@localhost>.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ifstat.c,v 1.3 2016/08/04 12:56:31 jakllsch Exp $");
+__RCSID("$NetBSD: ifstat.c,v 1.4 2016/08/05 07:22:17 christos Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -350,24 +350,11 @@
static void
right_align_string(struct if_stat *ifp)
{
- int str_len = 0, pad_len = 0;
- char *newstr = NULL, *ptr = NULL;
-
if (ifp == NULL || ifp->if_mib.ifdr_name[0] == '\0')
return;
- else {
- /* string length + '\0' */
- str_len = strlen(ifp->if_mib.ifdr_name)+1;
- pad_len = IF_NAMESIZE-(str_len);
- newstr = ifp->if_name;
- ptr = newstr + pad_len;
- (void)memset((void *)newstr, (int)' ', IF_NAMESIZE);
- (void)strncpy(ptr, (const char *)&ifp->if_mib.ifdr_name,
- str_len);
- }
-
- return;
+ snprintf(ifp->if_name, IF_NAMESIZE, "%*s", IF_NAMESIZE - 1,
+ ifp->if_mib.ifdr_name);
}
static int
Home |
Main Index |
Thread Index |
Old Index