src folder -> source folder; makes merging with dev a bit easier.
This commit is contained in:
30
source/libc/include/mem.h
Normal file
30
source/libc/include/mem.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
// NOTE: These should not be inline
|
||||
inline void* memset (void* ptr, int value, size_t num){
|
||||
for( int i = 0; i < num; i++ )
|
||||
{
|
||||
unsigned char* data = (unsigned char*)ptr+ i;
|
||||
*data = (unsigned char)value;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline int memcmp( const void* ptr1, const void* ptr2, size_t num)
|
||||
{
|
||||
const unsigned char * cs = (const unsigned char*) ptr1;
|
||||
const unsigned char * ct = (const unsigned char*) ptr2;
|
||||
|
||||
|
||||
for (int i = 0 ; i < num ; i++, cs++, ct++ ){
|
||||
if( *cs < *ct){
|
||||
return -1;
|
||||
} else if( *cs > *ct){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
26
source/libc/include/string.c
Normal file
26
source/libc/include/string.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "string.h"
|
||||
|
||||
size_t strlen(const char* str) {
|
||||
size_t len = 0;
|
||||
while(str[len]){
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int strncmp ( const char* str1, const char* str2, size_t num ){
|
||||
for( int i = 0; i < num ; i++){
|
||||
|
||||
if( str1[i] < str2[i]){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( str1[i] > str2[i] ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
6
source/libc/include/string.h
Normal file
6
source/libc/include/string.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
size_t strlen(const char* str);
|
||||
|
||||
|
||||
int strncmp ( const char* str1, const char* str2, size_t num );
|
Reference in New Issue
Block a user