Initial git commit of kernel code from latest version in fossil. This only includes the base kernel code and LICENSE, not any makefiles or dependencies from libc etc. (the build environment itself hasn't been moved over to git yet)

This commit is contained in:
2025-06-08 20:13:19 +10:00
parent 18a84697ef
commit c0efdc3b0f
62 changed files with 9395 additions and 0 deletions

82
string.c Normal file
View File

@ -0,0 +1,82 @@
// TODO: CHECK/REPLACE/UPDATE OLD CODE (this file is based on xv6)
#include "types.h"
#define KERNEL_MODE
#include <libc/string.c>
int
memcmp(const void *v1, const void *v2, uint n)
{
const uchar *s1, *s2;
s1 = v1;
s2 = v2;
while(n-- > 0){
if(*s1 != *s2)
return *s1 - *s2;
s1++, s2++;
}
return 0;
}
void*
memmove(void *dst, const void *src, uint n)
{
const char *s;
char *d;
if(n == 0)
return dst;
s = src;
d = dst;
if(s < d && s + n > d){
s += n;
d += n;
while(n-- > 0)
*--d = *--s;
} else {
#ifdef _ZCC
//if (n >= 8 && (d + n < s || s + n < d)) {
// return memcpy_opt(dst, src, n);
/*uint smalln = n %8;
uint bign = n - smalln;
memcpy_quick64(dst, src, bign);
d += bign;
s += bign;
n = smalln;*/
//}
#endif
while(n-- > 0)
*d++ = *s++;
}
return dst;
}
int
strncmp(const char *p, const char *q, uint n)
{
while(n > 0 && *p && *p == *q)
n--, p++, q++;
if(n == 0)
return 0;
return (uchar)*p - (uchar)*q;
}
// Like strncpy but guaranteed to NUL-terminate.
char*
safestrcpy(char *s, const char *t, int n)
{
char *os;
os = s;
if(n <= 0)
return os;
while(--n > 0 && (*s++ = *t++) != 0)
;
*s = 0;
return os;
}