diff options
Diffstat (limited to 'src/lib/strings.c')
-rw-r--r-- | src/lib/strings.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/lib/strings.c b/src/lib/strings.c index 8f62391..795caa2 100644 --- a/src/lib/strings.c +++ b/src/lib/strings.c @@ -1,6 +1,6 @@ #include "../lib/strings.h" -unsigned long strlen(char* s) { +unsigned long strlen(string_t s) { unsigned long len = 0; while (s[len] != 0) { len += 1; @@ -8,7 +8,7 @@ unsigned long strlen(char* s) { return len; } -unsigned char strcmp(char* a, char* b) { +unsigned char strcmp(string_t a, string_t b) { unsigned long idx = 0; while (a[idx] != 0 && b[idx] != 0) { if (a[idx] != b[idx]) { @@ -18,3 +18,14 @@ unsigned char strcmp(char* a, char* b) { } return a[idx] == b[idx]; } + +unsigned char strcmpn(string_t a, string_t b, unsigned int n) { + unsigned long idx = 0; + while (a[idx] != 0 && b[idx] != 0 && idx+1 < n) { + if (a[idx] != b[idx]) { + return 0; + } + idx += 1; + } + return a[idx] == b[idx]; +} |