aboutsummaryrefslogtreecommitdiff
path: root/string2.h
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-03-01 16:11:17 +0100
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-03-01 16:11:17 +0100
commit8d81ffef00f5cf2c267fb855715b76cdf004bc52 (patch)
treed1ffe2485627e8f64d6b1a908fad2ae872d1eee6 /string2.h
parent2392a52c10fdb32e504cb76d5f1989df7a643655 (diff)
downloadstring2-8d81ffef00f5cf2c267fb855715b76cdf004bc52.tar.gz
string2-8d81ffef00f5cf2c267fb855715b76cdf004bc52.zip
Keep it simple
Diffstat (limited to 'string2.h')
-rw-r--r--string2.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/string2.h b/string2.h
new file mode 100644
index 0000000..228cc8e
--- /dev/null
+++ b/string2.h
@@ -0,0 +1,17 @@
+/* See LICENSE file for copyright and license details. */
+
+#ifndef __STRING2_H__
+#define __STRING2_H__
+
+#include <string.h>
+
+#define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
+
+static int
+strends(const char *str, const char *suffix)
+{
+ int offset = strlen(str) - strlen(suffix);
+ return offset < 0 ? 0 : strcmp(str + offset, suffix) == 0;
+}
+
+#endif /* __STRING2_H__ */