OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [src/] [lib/] [string.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Copyright 2008-2010 B Labs Ltd.
3
 */
4
 
5
void *_memset(void *p, int c, int size);
6
void *_memcpy(void *d, void *s, int size);
7
 
8
void *memset(void *p, int c, int size)
9
{
10
        return _memset(p, c, size);
11
}
12
 
13
void *memcpy(void *d, void *s, int size)
14
{
15
        return _memcpy(d, s, size);
16
}
17
 
18
 
19
int strcmp(const char *s1, const char *s2)
20
{
21
        unsigned int i = 0;
22
        int d;
23
 
24
        while(1) {
25
                d = (unsigned char)s1[i] - (unsigned char)s2[i];
26
                if (d != 0 || s1[i] == '\0')
27
                        return d;
28
                i++;
29
        }
30
}
31
 
32
/*
33
 * Copies string pointed by @from to string pointed by @to.
34
 *
35
 * If count is greater than the length of string in @from,
36
 * pads rest of the locations with null.
37
 */
38
char *strncpy(char *to, const char *from, int count)
39
{
40
        char *temp = to;
41
 
42
        while (count) {
43
                *temp = *from;
44
 
45
                /*
46
                 * Stop updating from if null
47
                 * terminator is reached.
48
                 */
49
                if (*from)
50
                        from++;
51
                temp++;
52
                count--;
53
        }
54
        return to;
55
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.