blob: d3639154022576cf1b1eec58b29218a9cae00f6c [file] [log] [blame]
Eric Andersenaad1a882001-03-16 22:47:14 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) many different people.
Eric Andersencb81e642003-07-14 21:21:08 +00006 * If you wrote this, please acknowledge your work.
Eric Andersenaad1a882001-03-16 22:47:14 +00007 *
Bernhard Reutner-Fischerb1629b12006-05-19 19:29:19 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersenaad1a882001-03-16 22:47:14 +00009 */
10
11#include <stdio.h>
12#include <string.h>
13#include <ctype.h>
14#include "libbb.h"
15
16
17void trim(char *s)
18{
Rob Landley828548a2005-09-01 10:23:57 +000019 size_t len = strlen(s);
20 size_t lws;
Mark Whitley4b66dab2001-04-23 17:04:41 +000021
Eric Andersenaad1a882001-03-16 22:47:14 +000022 /* trim trailing whitespace */
Rob Landley828548a2005-09-01 10:23:57 +000023 while (len && isspace(s[len-1])) --len;
Eric Andersenaad1a882001-03-16 22:47:14 +000024
25 /* trim leading whitespace */
Rob Landley828548a2005-09-01 10:23:57 +000026 if(len) {
27 lws = strspn(s, " \n\r\t\v");
28 memmove(s, s + lws, len -= lws);
29 }
30 s[len] = 0;
Eric Andersenaad1a882001-03-16 22:47:14 +000031}