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>
This commit is contained in:
		
							
								
								
									
										12
									
								
								libbb/trim.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								libbb/trim.c
									
									
									
									
									
								
							@@ -10,9 +10,10 @@
 | 
			
		||||
 | 
			
		||||
#include "libbb.h"
 | 
			
		||||
 | 
			
		||||
void FAST_FUNC trim(char *s)
 | 
			
		||||
char* FAST_FUNC trim(char *s)
 | 
			
		||||
{
 | 
			
		||||
	size_t len = strlen(s);
 | 
			
		||||
	size_t old = len;
 | 
			
		||||
 | 
			
		||||
	/* trim trailing whitespace */
 | 
			
		||||
	while (len && isspace(s[len-1]))
 | 
			
		||||
@@ -26,5 +27,12 @@ void FAST_FUNC trim(char *s)
 | 
			
		||||
			memmove(s, nws, len);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	s[len] = '\0';
 | 
			
		||||
 | 
			
		||||
	s += len;
 | 
			
		||||
	/* If it was a "const char*" which does not need trimming,
 | 
			
		||||
	 * avoid superfluous store */
 | 
			
		||||
	if (old != len)
 | 
			
		||||
		*s = '\0';
 | 
			
		||||
 | 
			
		||||
	return s;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user