mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-29 05:38:21 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
objects := $(patsubst %.c,%.o,$(wildcard *.c))
|
||||
subdirs :=
|
||||
OBJPATH=$(OBJDIR)/include/string
|
||||
export
|
||||
|
||||
all: $(subdirs) $(objects)
|
||||
for subdir in $(subdirs) ; do $(MAKE) -C $${subdir} ; done
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
mkdir -p $(OBJPATH)
|
||||
cp $@ $(OBJPATH)/$@
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void* memcpy(void* d, void* s, size_t c){
|
||||
|
||||
uint8_t* sc = (uint8_t*)s;
|
||||
uint8_t* dc = (uint8_t*)d;
|
||||
|
||||
while(c--)
|
||||
*dc++ = *sc++;
|
||||
|
||||
return d;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <stddef.h>
|
||||
|
||||
void* memset(void* ptr, unsigned long value, size_t num){
|
||||
char* p = (char*)ptr;
|
||||
while(num--)
|
||||
*p++ = value;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
char *strcat(char *dest, const char * src){
|
||||
|
||||
dest += strlen(dest);
|
||||
|
||||
strcpy(dest, src);
|
||||
|
||||
return dest;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
int strcmp(const char* a, const char* b){
|
||||
|
||||
while(*a && (*a++ == *b++));
|
||||
|
||||
return *(const unsigned char*)a - *(const unsigned char*)b;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
void strcpy(char* p, const char * s)
|
||||
{
|
||||
const char * temp1 = s;
|
||||
char * temp2 = p;
|
||||
while(*temp1 != '\0')
|
||||
{
|
||||
*temp2 = *temp1;
|
||||
temp1++;
|
||||
temp2++;
|
||||
}
|
||||
*temp2 = '\0';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <stddef.h>
|
||||
|
||||
size_t strlen(const char* a){
|
||||
|
||||
size_t s = 0;
|
||||
while(a[s] != '\0') ++s;
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stddef.h>
|
||||
|
||||
int strncmp(const char *a, const char *b, size_t c){
|
||||
|
||||
int diff = 0;
|
||||
|
||||
while(c--)
|
||||
diff += *a++ - *b++;
|
||||
|
||||
|
||||
return diff;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user