diff options
Diffstat (limited to 'src/string2.h')
-rw-r--r-- | src/string2.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/string2.h b/src/string2.h new file mode 100644 index 0000000..228cc8e --- /dev/null +++ b/src/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__ */ |