summaryrefslogtreecommitdiffstats
path: root/src/lib/string.c
blob: c267c11d7fbc92df1e3b08cd995b0ff13baaceb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <string.h>

void* memset(void* s, int c, size_t n)
{
    char* _s = s;
    while(n)
    {
	*_s = c;
	_s++; n--;
    }
    return s;
}

char* strcpy(char* d, const char* s)
{
    char* d1 = d;

    do
    {
	*d1 = *s;
	if (*s == '\0') return d;
	d1++; s++;
    } while(1);
}

int strcmp(const char* a, const char* b)
{
    while((*a != '\0') && (*b != '\0'))
    {
	if (*a == *b)
	{
	    a++; b++;
	}
	else
	{
	    return (*a > *b) ? 1 : -1;
	}
    }
    if (*a == *b)
	return 0;
    if (*a == '\0')
	return -1;
    else
	return 1;
}
OpenPOWER on IntegriCloud