Fixes so "make allnoconfig" works again.
[oweals/busybox.git] / libbb / trim.c
index cb673cac3664c2d88358401414f53016b61ea272..0dca6678edf758985ae62e1a496e3ddfba39cca5 100644 (file)
@@ -2,8 +2,8 @@
 /*
  * Utility routines.
  *
- * Copyright (C) many different people.  If you wrote this, please
- * acknowledge your work.
+ * Copyright (C) many different people.
+ * If you wrote this, please acknowledge your work.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 void trim(char *s)
 {
-       int len = strlen(s);
+       size_t len = strlen(s);
+       size_t lws;
 
        /* trim trailing whitespace */
-       while ( len > 0 && isspace(s[len-1]))
-               s[--len]='\0';
+       while (len && isspace(s[len-1])) --len;
 
        /* trim leading whitespace */
-       memmove(s, &s[strspn(s, " \n\r\t\v")], len);
+       if(len) {
+               lws = strspn(s, " \n\r\t\v");
+               memmove(s, s + lws, len -= lws);
+       }
+       s[len] = 0;
 }
 
 /* END CODE */