Compare commits

...

5 commits

Author SHA1 Message Date
6c6f7eb902 Use wildcard for *.c files 2025-11-30 18:35:17 +03:00
007c6267ac Shouldn't check for 0, standard says func must put \0 anyways 2025-11-30 18:20:27 +03:00
b36822727e axl_strcmp 2025-11-30 18:19:14 +03:00
34e170d3b6 axl_strncat 2025-11-30 17:32:50 +03:00
a6514f595c axl_strcat 2025-11-30 17:18:38 +03:00
3 changed files with 72 additions and 2 deletions

View file

@ -6,7 +6,7 @@ u32 axl_strlen(const i8* s)
{
return 0;
}
u32 len = 0;
while(s[len] != '\0')
@ -52,3 +52,70 @@ i8* axl_strncpy(i8* dst, const i8* src, u32 n)
return dst;
}
i8* axl_strcat(i8* dst, const i8* src)
{
if(dst == NULL || src == NULL)
{
return dst;
}
return axl_strcpy(dst + axl_strlen(dst), src);
}
i8* axl_strncat(i8* dst, const i8* src, u32 n) //n actually means "not more than"
{
if(!dst || !src)
{
return dst;
}
i8* p = dst + axl_strlen(dst);
while (n-- && (*p++ = *src++)); //quick note: '\0' == 0
*p = '\0'; //in case we copied exactly n without '\0'
return dst;
}
i32 axl_strcmp(const i8* s1, const i8* s2)
{
if (!s1 || !s2)
{
return (s1 == s2) ? 0 : (!s1 ? -1 : 1);
}
for (;; s1++, s2++)
{
u8 c1 = *(const u8*)s1;
u8 c2 = *(const u8*)s2;
if (c1 != c2 || c1 == '\0' || c2 == '\0')
{
return c1 - c2;
}
}
return 0;
}
i32 axl_strncmp(const i8* s1, const i8* s2, u32 n)
{
if (!s1 || !s2)
{
return (s1 == s2) ? 0 : (!s1 ? -1 : 1);
}
for (u32 i = 0; i < n; s1++, s2++)
{
u8 c1 = *(const u8*)s1;
u8 c2 = *(const u8*)s2;
if (c1 != c2 || c1 == '\0' || c2 == '\0')
{
return c1 - c2;
}
}
return 0;
}

View file

@ -6,5 +6,8 @@
u32 axl_strlen(const i8* s);
i8* axl_strcpy(i8* dst, const i8* src);
i8* axl_strncpy(i8* dst, const i8* src, u32 n);
i8* axl_strcat(i8* dst, const i8* src);
i8* axl_strncat(i8* dst, const i8* src, u32 n);
i32 axl_strcmp(const i8* s1, const i8* s2);
#endif // AXL_STRING

View file

@ -2,7 +2,7 @@ CC = clang
CFLAGS = -Wall -Wextra -Werror -pedantic -std=c11 -nostdlib -static -Oz -ffreestanding
LDFLAGS = -Wl,/SUBSYSTEM:CONSOLE,/ENTRY:_start -fuse-ld=lld
LIBS = -lkernel32
SOURCES = main.c axl_memory.c
SOURCES = $(wildcard *.c)
TARGET = prog.exe
all: clean $(TARGET)