kern

annotate 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
rev   line source
nuclear@0 1 #include <string.h>
nuclear@0 2
nuclear@1 3 void memset(void *s, int c, size_t n)
nuclear@0 4 {
nuclear@0 5 char *ptr = s;
nuclear@1 6 while(n--) {
nuclear@0 7 *ptr++ = c;
nuclear@0 8 }
nuclear@0 9 }
nuclear@1 10
nuclear@2 11 void memset16(void *s, int c, size_t n)
nuclear@2 12 {
nuclear@2 13 short *ptr = s;
nuclear@2 14 while(n--) {
nuclear@2 15 *ptr++ = c;
nuclear@2 16 }
nuclear@2 17 }
nuclear@2 18
nuclear@1 19 void *memcpy(void *dest, const void *src, size_t n)
nuclear@1 20 {
nuclear@1 21 char *dptr = dest;
nuclear@1 22 const char *sptr = src;
nuclear@1 23
nuclear@1 24 while(n--) {
nuclear@1 25 *dptr++ = *sptr++;
nuclear@1 26 }
nuclear@1 27 return dest;
nuclear@1 28 }
nuclear@1 29
nuclear@1 30 void *memmove(void *dest, const void *src, size_t n)
nuclear@1 31 {
nuclear@1 32 int i;
nuclear@1 33 char *dptr;
nuclear@1 34 const char *sptr;
nuclear@1 35
nuclear@1 36 if(dest <= src) {
nuclear@1 37 /* forward copy */
nuclear@1 38 dptr = dest;
nuclear@1 39 sptr = src;
nuclear@1 40 for(i=0; i<n; i++) {
nuclear@1 41 *dptr++ = *sptr++;
nuclear@1 42 }
nuclear@1 43 } else {
nuclear@1 44 /* backwards copy */
nuclear@1 45 dptr = dest + n - 1;
nuclear@1 46 sptr = src + n - 1;
nuclear@1 47 for(i=0; i<n; i++) {
nuclear@1 48 *dptr-- = *sptr--;
nuclear@1 49 }
nuclear@1 50 }
nuclear@1 51
nuclear@1 52 return dest;
nuclear@1 53 }