aboutsummaryrefslogtreecommitdiff
path: root/src/lib/strings.c
blob: 795caa21011ff1ccc4eb0ecddd6fae0950be19cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "../lib/strings.h"

unsigned long strlen(string_t s) {
	unsigned long len = 0;
	while (s[len] != 0) {
		len += 1;
	}
	return len;
}

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]) {
			return 0;
		}
		idx += 1;
	}
	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];
}