]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/string-util.h
string-util: add new memory_startswith() helper
[thirdparty/systemd.git] / src / basic / string-util.h
index 5a10eeabfe90371f1fbd4a2ed13b32dfcb900dd3..aa007242663240f0f79d08e4455788bdbac8464d 100644 (file)
@@ -209,3 +209,21 @@ static inline size_t strlen_ptr(const char *s) {
 
         return strlen(s);
 }
+
+/* Like startswith(), but operates on arbitrary memory blocks */
+static inline void *memory_startswith(const void *p, size_t sz, const char *token) {
+        size_t n;
+
+        assert(token);
+
+        n = strlen(token);
+        if (sz < n)
+                return NULL;
+
+        assert(p);
+
+        if (memcmp(p, token, n) != 0)
+                return NULL;
+
+        return (uint8_t*) p + n;
+}