svn commit: r334527 - head/usr.bin/top

Eitan Adler eadler at FreeBSD.org
Sat Jun 2 08:46:10 UTC 2018


Author: eadler
Date: Sat Jun  2 08:46:09 2018
New Revision: 334527
URL: https://svnweb.freebsd.org/changeset/base/334527

Log:
  Use stpcpy instead of home grown solution

Modified:
  head/usr.bin/top/display.c
  head/usr.bin/top/utils.c
  head/usr.bin/top/utils.h

Modified: head/usr.bin/top/display.c
==============================================================================
--- head/usr.bin/top/display.c	Sat Jun  2 08:38:59 2018	(r334526)
+++ head/usr.bin/top/display.c	Sat Jun  2 08:46:09 2018	(r334527)
@@ -822,7 +822,7 @@ i_process(int line, char *thisline)
 
     /* copy it in to our buffer */
     base = smart_terminal ? screenbuf + lineindex(line) : screenbuf;
-    p = strecpy(base, thisline);
+    p = stpcpy(base, thisline);
 
     /* zero fill the rest of it */
     bzero(p, display_width - (p - base));
@@ -861,7 +861,7 @@ u_process(int line, char *newline)
 	fputs(newline, stdout);
 
 	/* copy it in to the buffer */
-	optr = strecpy(bufferline, newline);
+	optr = stpcpy(bufferline, newline);
 
 	/* zero fill the rest of it */
 	bzero(optr, display_width - (optr - bufferline));
@@ -1110,30 +1110,30 @@ static void summary_format(char *str, int *numbers, ch
 	    if (thisname[0] == 'K')
 	    {
 		/* yes: format it as a memory value */
-		p = strecpy(p, format_k(num));
+		p = stpcpy(p, format_k(num));
 
 		/* skip over the K, since it was included by format_k */
-		p = strecpy(p, thisname+1);
+		p = stpcpy(p, thisname+1);
 	    }
 	    /* is this number a ratio? */
 	    else if (thisname[0] == ':')
 	    {
 		(void) snprintf(rbuf, sizeof(rbuf), "%.2f", 
 		    (float)*(numbers - 2) / (float)num);
-		p = strecpy(p, rbuf);
-		p = strecpy(p, thisname);
+		p = stpcpy(p, rbuf);
+		p = stpcpy(p, thisname);
 	    }
 	    else
 	    {
-		p = strecpy(p, itoa(num));
-		p = strecpy(p, thisname);
+		p = stpcpy(p, itoa(num));
+		p = stpcpy(p, thisname);
 	    }
 	}
 
 	/* ignore negative numbers, but display corresponding string */
 	else if (num < 0)
 	{
-	    p = strecpy(p, thisname);
+	    p = stpcpy(p, thisname);
 	}
     }
 

Modified: head/usr.bin/top/utils.c
==============================================================================
--- head/usr.bin/top/utils.c	Sat Jun  2 08:38:59 2018	(r334526)
+++ head/usr.bin/top/utils.c	Sat Jun  2 08:46:09 2018	(r334527)
@@ -131,18 +131,6 @@ int digits(int val)
 }
 
 /*
- *  strecpy(to, from) - copy string "from" into "to" and return a pointer
- *	to the END of the string "to".
- */
-
-char *
-strecpy(char *to, const char *from)
-{
-    while ((*to++ = *from++) != '\0');
-    return(--to);
-}
-
-/*
  * string_index(string, array) - find string in array and return index
  */
 
@@ -393,7 +381,7 @@ char *format_k(int amt)
 	}
     }
 
-    p = strecpy(p, itoa(amt));
+    p = stpcpy(p, itoa(amt));
     *p++ = tag;
     *p = '\0';
 
@@ -423,7 +411,7 @@ format_k2(unsigned long long amt)
 	}
     }
 
-    p = strecpy(p, itoa((int)amt));
+    p = stpcpy(p, itoa((int)amt));
     *p++ = tag;
     *p = '\0';
 

Modified: head/usr.bin/top/utils.h
==============================================================================
--- head/usr.bin/top/utils.h	Sat Jun  2 08:38:59 2018	(r334526)
+++ head/usr.bin/top/utils.h	Sat Jun  2 08:46:09 2018	(r334527)
@@ -14,7 +14,6 @@ int atoiwi(const char *);
 char *itoa(unsigned int);
 char *itoa7(unsigned int);
 int digits(int);
-char *strecpy(char *, const char *);
 char **argparse(char *, int *);
 long percentages(int, int *, long *, long *, long *);
 char *format_time(long);


More information about the svn-src-all mailing list