aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-06-13 12:59:34 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-06-13 12:59:34 -0400
commit9f235ec8ee1d9a08519707aed4b698867889b7fa (patch)
tree21f11413af0f9f9922399fc0a754ac9c05b092cd
parent3259fe64acbf25f12185e967c9d389064463db37 (diff)
downloadohmycal-9f235ec8ee1d9a08519707aed4b698867889b7fa.tar.gz
Prevent false-positive result
* Return zero on error
-rw-r--r--include/str.h4
-rw-r--r--src/str.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/include/str.h b/include/str.h
index 895b8cc..595a055 100644
--- a/include/str.h
+++ b/include/str.h
@@ -29,7 +29,7 @@ int num_chars(const char *sptr, int ch);
*
* @param sptr string to scan
* @param pattern string to search for
- * @return 1 = found, 0 = not found, -1 = error
+ * @return 1 = found, 0 = not found / error
*/
int startswith(const char *sptr, const char *pattern);
@@ -38,7 +38,7 @@ int startswith(const char *sptr, const char *pattern);
*
* @param sptr string to scan
* @param pattern string to search for
- * @return 1 = found, 0 = not found, -1 = error
+ * @return 1 = found, 0 = not found / error
*/
int endswith(const char *sptr, const char *pattern);
diff --git a/src/str.c b/src/str.c
index f27e946..16088b6 100644
--- a/src/str.c
+++ b/src/str.c
@@ -16,7 +16,7 @@ int num_chars(const char *sptr, int ch) {
int startswith(const char *sptr, const char *pattern) {
if (!sptr || !pattern) {
- return -1;
+ return 0;
}
for (size_t i = 0; i < strlen(pattern); i++) {
if (sptr[i] != pattern[i]) {
@@ -28,7 +28,7 @@ int startswith(const char *sptr, const char *pattern) {
int endswith(const char *sptr, const char *pattern) {
if (!sptr || !pattern) {
- return -1;
+ return 0;
}
ssize_t sptr_size = (ssize_t) strlen(sptr);
ssize_t pattern_size = (ssize_t) strlen(pattern);