Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Utility routines. |
| 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) many different people. |
Eric Andersen | cb81e64 | 2003-07-14 21:21:08 +0000 | [diff] [blame] | 6 | * If you wrote this, please acknowledge your work. |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 7 | * |
Bernhard Reutner-Fischer | b1629b1 | 2006-05-19 19:29:19 +0000 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <string.h> |
| 13 | #include <ctype.h> |
| 14 | #include "libbb.h" |
| 15 | |
| 16 | |
| 17 | void trim(char *s) |
| 18 | { |
Rob Landley | 828548a | 2005-09-01 10:23:57 +0000 | [diff] [blame] | 19 | size_t len = strlen(s); |
| 20 | size_t lws; |
Mark Whitley | 4b66dab | 2001-04-23 17:04:41 +0000 | [diff] [blame] | 21 | |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 22 | /* trim trailing whitespace */ |
Rob Landley | 828548a | 2005-09-01 10:23:57 +0000 | [diff] [blame] | 23 | while (len && isspace(s[len-1])) --len; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 24 | |
| 25 | /* trim leading whitespace */ |
Rob Landley | 828548a | 2005-09-01 10:23:57 +0000 | [diff] [blame] | 26 | if(len) { |
| 27 | lws = strspn(s, " \n\r\t\v"); |
| 28 | memmove(s, s + lws, len -= lws); |
| 29 | } |
| 30 | s[len] = 0; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 31 | } |