Compare commits
5 commits
2f31564ce2
...
6c6f7eb902
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c6f7eb902 | |||
| 007c6267ac | |||
| b36822727e | |||
| 34e170d3b6 | |||
| a6514f595c |
3 changed files with 72 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
2
makefile
2
makefile
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue