--- trim.c 2008-08-03 11:02:17.000000000 -0400 +++ kate-trim-my-rtrim.c 2008-12-17 19:07:00.000000000 -0500 @@ -1,6 +1,7 @@ /* $Id: trim.c 304 2008-08-03 15:02:17Z kate $ */ /* + * originally: http://elide.org/snippets/trim.c * Trim whitespace. */ @@ -33,12 +34,12 @@ char * rtrim(char *s) { char *p = s + strlen(s) - 1; - + const char *end = p; while (p >= s && isspace((unsigned char) *p)) { - *p = '\0'; p--; } - + if (p != end) + *p = '\0'; return s; }