summaryrefslogtreecommitdiffstats
path: root/daemon/guestfsd.c
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-03-18 13:46:26 +0000
committerRichard Jones <rjones@redhat.com>2010-03-18 15:21:04 +0000
commit27e73269d384814eb5f76468f609f7844cb75b0b (patch)
treeb336ea3b156f67d9676d0707ee5b781919e81003 /daemon/guestfsd.c
parent676462684e05dd8341dd695762dd99a87d8ec022 (diff)
downloadlibguestfs-27e73269d384814eb5f76468f609f7844cb75b0b.tar.gz
libguestfs-27e73269d384814eb5f76468f609f7844cb75b0b.tar.xz
libguestfs-27e73269d384814eb5f76468f609f7844cb75b0b.zip
daemon: Add a trim utility function.
This function trims the whitespace from around a string. It does this in-place, so it can be called for malloc'd strings.
Diffstat (limited to 'daemon/guestfsd.c')
-rw-r--r--daemon/guestfsd.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 0fc01283..5265ab52 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -928,6 +928,28 @@ split_lines (char *str)
return lines;
}
+/* Skip leading and trailing whitespace, updating the original string
+ * in-place.
+ */
+void
+trim (char *str)
+{
+ size_t len = strlen (str);
+
+ while (len > 0 && c_isspace (str[len-1])) {
+ str[len-1] = '\0';
+ len--;
+ }
+
+ const char *p = str;
+ while (*p && c_isspace (*p)) {
+ p++;
+ len--;
+ }
+
+ memmove (str, p, len+1);
+}
+
/* printf helper function so we can use %Q ("quoted") and %R to print
* shell-quoted strings. See HACKING file for more details.
*/