[CRIU] [PATCH 1/7] util: Introduce strstartswith helper

Pavel Emelyanov xemul at parallels.com
Thu May 8 06:07:23 PDT 2014


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 include/util.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/util.h b/include/util.h
index c4b8e69..40dd1dc 100644
--- a/include/util.h
+++ b/include/util.h
@@ -277,4 +277,22 @@ extern int read_fd_link(int lfd, char *buf, size_t size);
 
 int vaddr_to_pfn(unsigned long vaddr, u64 *pfn);
 
+/*
+ * Check whether @str starts with @sub
+ */
+static inline bool strstartswith(char *str, char *sub)
+{
+	while (1) {
+		if (*sub == '\0') /* end of sub -- match */
+			return true;
+		if (*str == '\0') /* end of str, sub is NOT ended -- miss */
+			return false;
+		if (*str != *sub)
+			return false;
+
+		str++;
+		sub++;
+	}
+}
+
 #endif /* __CR_UTIL_H__ */
-- 
1.8.4.2


More information about the CRIU mailing list