Xv6 with picoc & Linkage editor  v1.0
The project delineate mutual cohesion between c library, linkage editor ( linker), interpreter and operating system by porting the same on xv6 kernel
string.c
00001 #include "types.h"
00002 #include "x86.h"
00003 
00004 void*
00005 memset(void *dst, int c, uint n)
00006 {
00007   if ((int)dst%4 == 0 && n%4 == 0){
00008     c &= 0xFF;
00009     stosl(dst, (c<<24)|(c<<16)|(c<<8)|c, n/4);
00010   } else
00011     stosb(dst, c, n);
00012   return dst;
00013 }
00014 
00015 int
00016 memcmp(const void *v1, const void *v2, uint n)
00017 {
00018   const uchar *s1, *s2;
00019   
00020   s1 = v1;
00021   s2 = v2;
00022   while(n-- > 0){
00023     if(*s1 != *s2)
00024       return *s1 - *s2;
00025     s1++, s2++;
00026   }
00027 
00028   return 0;
00029 }
00030 void*
00031 memmove(void *dst, const void *src, uint n)
00032 {
00033   const char *s;
00034   char *d;
00035 
00036   s = src;
00037   d = dst;
00038   if(s < d && s + n > d){
00039     s += n;
00040     d += n;
00041     while(n-- > 0)
00042       *--d = *--s;
00043   } else
00044     while(n-- > 0)
00045       *d++ = *s++;
00046 
00047   return dst;
00048 }
00049 
00050 // memcpy exists to placate GCC.  Use memmove.
00051 void*
00052 memcpy(void *dst, const void *src, uint n)
00053 {
00054   return memmove(dst, src, n);
00055 }
00056 
00057 int
00058 strncmp(const char *p, const char *q, uint n)
00059 {
00060   while(n > 0 && *p && *p == *q)
00061     n--, p++, q++;
00062   if(n == 0)
00063     return 0;
00064   return (uchar)*p - (uchar)*q;
00065 }
00066 
00067 char*
00068 strncpy(char *s, const char *t, int n)
00069 {
00070   char *os;
00071   
00072   os = s;
00073   while(n-- > 0 && (*s++ = *t++) != 0)
00074     ;
00075   while(n-- > 0)
00076     *s++ = 0;
00077   return os;
00078 }
00079 
00080 // Like strncpy but guaranteed to NUL-terminate.
00081 char*
00082 safestrcpy(char *s, const char *t, int n)
00083 {
00084   char *os;
00085   
00086   os = s;
00087   if(n <= 0)
00088     return os;
00089   while(--n > 0 && (*s++ = *t++) != 0)
00090     ;
00091   *s = 0;
00092   return os;
00093 }
00094 
00095 int
00096 strlen(const char *s)
00097 {
00098   int n;
00099 
00100   for(n = 0; s[n]; n++)
00101     ;
00102   return n;
00103 }
00104 
 All Data Structures