mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Function strstrip strips leading and trailung spaces from a given string. During review it was decided to move this function to the libutil library to make it available for other tools. Signed-off-by: Thomas Richter <tmricht@linux.vnet.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
40 lines
603 B
C
40 lines
603 B
C
/*
|
|
* util - Utility function library
|
|
*
|
|
* Strip leading and trailing blanks.
|
|
*
|
|
* Copyright IBM Corp. 2018
|
|
*
|
|
* s390-tools is free software; you can redistribute it and/or modify
|
|
* it under the terms of the MIT license. See LICENSE for details.
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
#include "lib/util_str.h"
|
|
|
|
/*
|
|
* strip leading and trailing blanks
|
|
*/
|
|
char *util_strstrip(char *s)
|
|
{
|
|
size_t size;
|
|
char *end;
|
|
|
|
size = strlen(s);
|
|
|
|
if (!size)
|
|
return s;
|
|
|
|
end = s + size - 1;
|
|
while (end >= s && isspace(*end))
|
|
end--;
|
|
*(end + 1) = '\0';
|
|
|
|
while (*s && isspace(*s))
|
|
s++;
|
|
|
|
return s;
|
|
}
|