[PATCH 1/5] misc: add xrtrim() - right-trim a string
Daniel Martin
consume.noise at gmail.com
Sat Dec 7 07:48:46 PST 2013
Signed-off-by: Daniel Martin <consume.noise at gmail.com>
---
include/misc.h | 1 +
os/utils.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/include/misc.h b/include/misc.h
index 17de710..aab556a 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -246,6 +246,7 @@ padding_for_int32(const int bytes)
}
+extern int xrtrim(char *str, int str_len);
extern char **xstrtokenize(const char *str, const char *separators);
extern void FormatInt64(int64_t num, char *string);
extern void FormatUInt64(uint64_t num, char *string);
diff --git a/os/utils.c b/os/utils.c
index fb20da7..56a1a6d 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1943,6 +1943,22 @@ CheckUserAuthorization(void)
}
/*
+ * Right-trim a string. Returns the string length after trimming.
+ */
+int
+xrtrim(char *str, int str_len)
+{
+ int i = str_len;
+
+ while (i > 0 && !isgraph(str[i - 1]))
+ i--;
+
+ str[i] = '\0';
+
+ return i;
+}
+
+/*
* Tokenize a string into a NULL terminated array of strings. Always returns
* an allocated array unless an error occurs.
*/
--
1.8.4.2
More information about the xorg-devel
mailing list