Line | Count | Source |
1 | ||
2 | // | |
3 | // str-ends-with.c | |
4 | // | |
5 | // Copyright (c) 2013 Stephen Mathieson | |
6 | // MIT licensed | |
7 | // | |
8 | ||
9 | #include <string.h> | |
10 | #include <stdbool.h> | |
11 | #include "str-ends-with.h" | |
12 | ||
13 | 0 | bool str_ends_with(const char *str, const char *end) { |
14 | 0 | int end_len; |
15 | 0 | int str_len; |
16 | ||
17 | 0 | if (NULL == str || NULL == end) return false; |
18 | ||
19 | 0 | end_len = strlen(end); |
20 | 0 | str_len = strlen(str); |
21 | ||
22 | 0 | return str_len < end_len |
23 | 0 | ? false |
24 | 0 | : !strcmp(str + str_len - end_len, end); |
25 | 0 | } |