kern

view src/klibc/string.c @ 1:ebe5e0e44a9d

pretty much finished the code for article 1, might do minor adjustments though
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 02 Dec 2010 08:45:41 +0200
parents 662ff2170531
children 86781ef20689
line source
1 #include <string.h>
3 void memset(void *s, int c, size_t n)
4 {
5 char *ptr = s;
6 while(n--) {
7 *ptr++ = c;
8 }
9 }
11 void *memcpy(void *dest, const void *src, size_t n)
12 {
13 char *dptr = dest;
14 const char *sptr = src;
16 while(n--) {
17 *dptr++ = *sptr++;
18 }
19 return dest;
20 }
22 void *memmove(void *dest, const void *src, size_t n)
23 {
24 int i;
25 char *dptr;
26 const char *sptr;
28 if(dest <= src) {
29 /* forward copy */
30 dptr = dest;
31 sptr = src;
32 for(i=0; i<n; i++) {
33 *dptr++ = *sptr++;
34 }
35 } else {
36 /* backwards copy */
37 dptr = dest + n - 1;
38 sptr = src + n - 1;
39 for(i=0; i<n; i++) {
40 *dptr-- = *sptr--;
41 }
42 }
44 return dest;
45 }