aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-05 17:50:35 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-05 17:50:35 +0200
commit20077c1429915b2c223e4d179a033f2b1806872c (patch)
tree76c89e23adc5bb529e310d9e25e7016f6d699645 /libbb
parent9cf89cdf84fb20154088145980b676d2b28fc55d (diff)
downloadbusybox-w32-20077c1429915b2c223e4d179a033f2b1806872c.tar.gz
busybox-w32-20077c1429915b2c223e4d179a033f2b1806872c.tar.bz2
busybox-w32-20077c1429915b2c223e4d179a033f2b1806872c.zip
libbb: make trim() return pointer to terminating NUL
function old new delta trim 80 90 +10 angle_address 56 50 -6 sysctl_main 282 273 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: +10/-15) Total: -5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/trim.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/libbb/trim.c b/libbb/trim.c
index 16cb4fbb0..e47fec74e 100644
--- a/libbb/trim.c
+++ b/libbb/trim.c
@@ -10,9 +10,10 @@
10 10
11#include "libbb.h" 11#include "libbb.h"
12 12
13void FAST_FUNC trim(char *s) 13char* FAST_FUNC trim(char *s)
14{ 14{
15 size_t len = strlen(s); 15 size_t len = strlen(s);
16 size_t old = len;
16 17
17 /* trim trailing whitespace */ 18 /* trim trailing whitespace */
18 while (len && isspace(s[len-1])) 19 while (len && isspace(s[len-1]))
@@ -26,5 +27,12 @@ void FAST_FUNC trim(char *s)
26 memmove(s, nws, len); 27 memmove(s, nws, len);
27 } 28 }
28 } 29 }
29 s[len] = '\0'; 30
31 s += len;
32 /* If it was a "const char*" which does not need trimming,
33 * avoid superfluous store */
34 if (old != len)
35 *s = '\0';
36
37 return s;
30} 38}