diff options
author | Karel Zak | 2014-08-25 15:31:53 +0200 |
---|---|---|
committer | Karel Zak | 2014-08-25 15:31:53 +0200 |
commit | 22e9e9c8e95e609a20f24ec60fcd706f601e0be7 (patch) | |
tree | 4d3c6af7447947e819158327eb4eeceed5b47a0d /include/strutils.h | |
parent | libfdisk: basic fdisk_dump_* functions (diff) | |
download | kernel-qcow2-util-linux-22e9e9c8e95e609a20f24ec60fcd706f601e0be7.tar.gz kernel-qcow2-util-linux-22e9e9c8e95e609a20f24ec60fcd706f601e0be7.tar.xz kernel-qcow2-util-linux-22e9e9c8e95e609a20f24ec60fcd706f601e0be7.zip |
libblkid: move string trim function to strutils.h
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/strutils.h')
-rw-r--r-- | include/strutils.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/include/strutils.h b/include/strutils.h index 3883b4288..cfe8a9560 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -161,4 +161,41 @@ static inline const char *skip_blank(const char *p) return p; } + +/* Removes whitespace from the right-hand side of a string (trailing + * whitespace). + * + * Returns size of the new string (without \0). + */ +static inline size_t rtrim_whitespace(unsigned char *str) +{ + size_t i = strlen((char *) str); + + while (i--) { + if (!isspace(str[i])) + break; + } + str[++i] = '\0'; + return i; +} + +/* Removes whitespace from the left-hand side of a string. + * + * Returns size of the new string (without \0). + */ +static inline size_t ltrim_whitespace(unsigned char *str) +{ + size_t len; + unsigned char *p; + + for (p = str; p && isspace(*p); p++); + + len = strlen((char *) p); + + if (len && p > str) + memmove(str, p, len + 1); + + return len; +} + #endif |