view src/string.c @ 99:2a0aa3efc228

The shell script will now theroretically load the program into memory, will not run it. The shell script loads a program into memory and displays the address but as of now does not jump to it (though it does display the address it would jump to) Added a memset function Added a python script (credit for its writing to Jeff) that sets up a filesystem
author Jonathan Pevarnek <pevarnj@gmail.com>
date Sat, 14 May 2011 19:40:18 -0400
parents 191e99dffd6c
children
line wrap: on
line source

int strcmp(const char *a, const char *b)
{
	while(1) {
		if(*a - *b) return *a - *b;
		if(*a == '\0') return 0;
		a++;
		b++;
	}
	return -1;
}

void strcpy(char *dest, const char *src)
{
	while((*dest++ = *src++));
}

char* strcat(char *dest, const char *src)
{
	char *ret = dest;
	while(*dest&& *++dest); //get to null in first string
	while((*dest++ = *src++));
	return ret;
}

void* memcpy(void *dest, const void *src, size_t num)
{
	size_t i;
	const u8 *from = src;
	u8 *to = dest;
	for(i = 0; i < num; i++)
		to[i] = from[i];
	return dest;
}

void* memset(void *dest, u8 value, size_t num)
{
	size_t i;
	u8 *ptr = dest;
	for(i = 0; i < num; i++, ptr++) {
		*ptr = value;
	}
	return dest;
}

size_t strlen(const char *str)
{
	const char *ptr = str;
	while(*ptr && *++ptr);
	return ptr - str;
}