Add and use HAS_PREFIX() and CHECK_AND_SKIP_PREFIX() for checking if string has liter...
[openssl.git] / include / internal / cryptlib.h
index 1291299b6e50ea129ba77c85bb0b21b0997e4494..1b700639d9776a0af71cbd59012ee63ec5f02b44 100644 (file)
@@ -45,6 +45,12 @@ __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
 
 #endif
 
+/* Check if pre, which must be a string literal, is a prefix of str */
+# define HAS_PREFIX(str, pre) (strncmp(str, pre "", sizeof(pre) - 1) == 0)
+/* As before, and if check succeeds, advance the str ptr past the prefix */
+# define CHECK_AND_SKIP_PREFIX(str, pre) \
+    (HAS_PREFIX(str, pre) ? ((str) += sizeof(pre) - 1, 1) : 0)
+
 /*
  * Use this inside a union with the field that needs to be aligned to a
  * reasonable boundary for the platform.  The most pessimistic alignment