kern

view src/klibc/string.c @ 2:86781ef20689

added hardware scrolling, memset16 and temporary keyboard input for testing
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 04 Dec 2010 08:04:43 +0200
parents ebe5e0e44a9d
children 0489a34ab348
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 memset16(void *s, int c, size_t n)
12 {
13 short *ptr = s;
14 while(n--) {
15 *ptr++ = c;
16 }
17 }
19 void *memcpy(void *dest, const void *src, size_t n)
20 {
21 char *dptr = dest;
22 const char *sptr = src;
24 while(n--) {
25 *dptr++ = *sptr++;
26 }
27 return dest;
28 }
30 void *memmove(void *dest, const void *src, size_t n)
31 {
32 int i;
33 char *dptr;
34 const char *sptr;
36 if(dest <= src) {
37 /* forward copy */
38 dptr = dest;
39 sptr = src;
40 for(i=0; i<n; i++) {
41 *dptr++ = *sptr++;
42 }
43 } else {
44 /* backwards copy */
45 dptr = dest + n - 1;
46 sptr = src + n - 1;
47 for(i=0; i<n; i++) {
48 *dptr-- = *sptr--;
49 }
50 }
52 return dest;
53 }