summaryrefslogtreecommitdiff
path: root/libpam/include/pam_inline.h
diff options
context:
space:
mode:
Diffstat (limited to 'libpam/include/pam_inline.h')
-rw-r--r--libpam/include/pam_inline.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/libpam/include/pam_inline.h b/libpam/include/pam_inline.h
index d93f8474..2e3a8d6a 100644
--- a/libpam/include/pam_inline.h
+++ b/libpam/include/pam_inline.h
@@ -9,6 +9,7 @@
#define PAM_INLINE_H
#include "pam_cc_compat.h"
+#include <string.h>
/*
* Evaluates to
@@ -34,4 +35,18 @@
/* Evaluates to the number of elements in the specified array. */
#define PAM_ARRAY_SIZE(a_) (sizeof(a_) / sizeof((a_)[0]) + PAM_MUST_BE_ARRAY(a_))
+/*
+ * Returns NULL if STR does not start with PREFIX,
+ * or a pointer to the first char in STR after PREFIX.
+ * The length of PREFIX is specified by PREFIX_LEN.
+ */
+static inline const char *
+pam_str_skip_prefix_len(const char *str, const char *prefix, size_t prefix_len)
+{
+ return strncmp(str, prefix, prefix_len) ? NULL : str + prefix_len;
+}
+
+#define pam_str_skip_prefix(str_, prefix_) \
+ pam_str_skip_prefix_len((str_), (prefix_), sizeof(prefix_) - 1 + PAM_MUST_BE_ARRAY(prefix_))
+
#endif /* PAM_INLINE_H */