summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEric Bénard <eric@eukrea.com>2012-07-05 12:22:45 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-07-05 20:58:54 +0200
commit7baead578db7e47aedfcd3a5a21a69b9f37630d1 (patch)
tree175a763e51abad3051eda1a65eefddb91024dd31 /lib
parentc6e82ee5437618cf09c0955839b4a2b1b167cc4a (diff)
downloadbarebox-7baead578db7e47aedfcd3a5a21a69b9f37630d1.tar.gz
barebox-7baead578db7e47aedfcd3a5a21a69b9f37630d1.tar.xz
string: add strim for ONFI code
Signed-off-by: Eric Bénard <eric@eukrea.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c
index 28650883cc..db4f2ae7db 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -567,3 +567,42 @@ void *memchr(const void *s, int c, size_t n)
#endif
EXPORT_SYMBOL(memchr);
+/**
+ * skip_spaces - Removes leading whitespace from @str.
+ * @str: The string to be stripped.
+ *
+ * Returns a pointer to the first non-whitespace character in @str.
+ */
+char *skip_spaces(const char *str)
+{
+ while (isspace(*str))
+ ++str;
+ return (char *)str;
+}
+
+/**
+ * strim - Removes leading and trailing whitespace from @s.
+ * @s: The string to be stripped.
+ *
+ * Note that the first trailing whitespace is replaced with a %NUL-terminator
+ * in the given string @s. Returns a pointer to the first non-whitespace
+ * character in @s.
+ */
+char *strim(char *s)
+{
+ size_t size;
+ char *end;
+
+ s = skip_spaces(s);
+ size = strlen(s);
+ if (!size)
+ return s;
+
+ end = s + size - 1;
+ while (end >= s && isspace(*end))
+ end--;
+ *(end + 1) = '\0';
+
+ return s;
+}
+EXPORT_SYMBOL(strim);