diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-12-19 00:41:43 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-12-19 00:41:43 -0500 |
commit | b3fcaefd320b0b4999d2d380139ab8610c6a0233 (patch) | |
tree | 1cc11b783eb9e8dc1e4b63c3ea27b91798d47b3c /src/strings.c | |
parent | 534657dd6fc2ee98159e41d2700554fed0da2c4e (diff) | |
download | spmc-b3fcaefd320b0b4999d2d380139ab8610c6a0233.tar.gz |
Make command line argument a thing
Diffstat (limited to 'src/strings.c')
-rw-r--r-- | src/strings.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/strings.c b/src/strings.c index ad784d1..87d2eca 100644 --- a/src/strings.c +++ b/src/strings.c @@ -21,12 +21,15 @@ int num_chars(const char *sptr, int ch) { * * @param sptr string to scan * @param pattern string to search for - * @return 0 = success, -1 = failure + * @return 0 = found, 1 = not found, -1 = error */ int startswith(const char *sptr, const char *pattern) { + if (!sptr) { + return -1; + } for (size_t i = 0; i < strlen(pattern); i++) { if (sptr[i] != pattern[i]) { - return -1; + return 1; } } return 0; @@ -37,14 +40,17 @@ int startswith(const char *sptr, const char *pattern) { * * @param sptr string to scan * @param pattern string to search for - * @return 0 = success, -1 = failure + * @return 0 = found, 1 = not found, -1 = error */ int endswith(const char *sptr, const char *pattern) { + if (!sptr) { + return -1; + } size_t sptr_size = strlen(sptr); size_t pattern_size = strlen(pattern); for (size_t s = sptr_size - pattern_size, p = 0 ; s < sptr_size; s++, p++) { if (sptr[s] != pattern[p]) { - return -1; + return 1; } } return 0; |