Skip to content

Commit 4fc024e

Browse files
committed
Added strlen and strcmp functions
1 parent ac15c80 commit 4fc024e

File tree

7 files changed

+36
-0
lines changed

7 files changed

+36
-0
lines changed

OS.iso

0 Bytes
Binary file not shown.

build/OS.bin

165 Bytes
Binary file not shown.

build/full_kernel.bin

165 Bytes
Binary file not shown.

build/output.c.o

1.05 KB
Binary file not shown.

iso/floppy.img

0 Bytes
Binary file not shown.

kernel/lib/std/io.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ extern uint16_t print_char(
4242

4343
extern void clear(uint16_t* _tty_buf, color_t _c);
4444

45+
/* Calculates string length _s
46+
returns length of string
47+
*/
48+
extern uint16_t strlen(const char* _s);
49+
50+
/* Compares string _s1 with string _s2
51+
return true if _s1 = _s2
52+
*/
53+
extern bool strcmp(const char* _s1, const char* _s2);
54+
4555
#endif

kernel/lib/std/output.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,30 @@ void clear(uint16_t* _tty_buf, color_t _c)
3232
for (uint8_t h = 0; h < VGA_HEIGHT; h++)
3333
for (uint8_t w = 0; w < VGA_WIDTH; w++)
3434
print_char(0x20, _c, h * VGA_WIDTH + w, _tty_buf);
35+
}
36+
37+
uint16_t strlen(const char* _s)
38+
{
39+
uint16_t len = 0;
40+
while (_s[len] != 0x00)
41+
len++ ;
42+
return len;
43+
}
44+
45+
bool strcmp(const char* _s1, const char* _s2)
46+
{
47+
uint16_t s1_len = strlen(_s1); // Length of first string
48+
if (strlen(_s1) == strlen(_s2))
49+
{
50+
uint16_t i = 0;
51+
while (_s1[i] == _s2[i]) // Char by char comparison
52+
i++;
53+
54+
if (i == s1_len) /*
55+
If amount of iterations equals string length
56+
means strings are equal
57+
*/
58+
return true;
59+
}
60+
return false;
3561
}

0 commit comments

Comments
 (0)