process control and context switch
This commit is contained in:
72
common.c
72
common.c
@@ -1,5 +1,41 @@
|
||||
#include "common.h"
|
||||
|
||||
void *memcpy(void *dst, const void *src, size_t n) {
|
||||
uint8_t *d = (uint8_t *) dst;
|
||||
const uint8_t *s = (const uint8_t *) src;
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memset(void *buf, char c, size_t n) {
|
||||
uint8_t *p = (uint8_t *) buf;
|
||||
while (n--)
|
||||
*p++ = c;
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *strcpy(char *dst, const char *src) {
|
||||
char *d = dst;
|
||||
while (*src)
|
||||
*d++ = *src++;
|
||||
*d = '\0';
|
||||
return dst;
|
||||
} // The strcpy function continues copying even if
|
||||
// src is longer than the memory area of dst.
|
||||
// This can easily lead to bugs and vulnerabilities
|
||||
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
while (*s1 && *s2) {
|
||||
if (*s1 != *s2)
|
||||
break;
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return *(unsigned char *)s1 - *(unsigned char *)s2;
|
||||
}
|
||||
|
||||
void putchar(char ch);
|
||||
|
||||
void printf(const char *fmt, ...) {
|
||||
@@ -62,39 +98,3 @@ void printf(const char *fmt, ...) {
|
||||
end:
|
||||
va_end(vargs);
|
||||
}
|
||||
|
||||
void *memcpy(void *dst, const void *src, size_t n) {
|
||||
uint8_t *d = (uint8_t *) dst;
|
||||
const uint8_t *s = (const uint8_t *) src;
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memset(void *buf, char c, size_t n) {
|
||||
uint8_t *p = (uint8_t *) buf;
|
||||
while (n--)
|
||||
*p++ = c;
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *strcpy(char *dst, const char *src) {
|
||||
char *d = dst;
|
||||
while (*src)
|
||||
*d++ = *src++;
|
||||
*d = '\0';
|
||||
return dst;
|
||||
} // The strcpy function continues copying even if
|
||||
// src is longer than the memory area of dst.
|
||||
// This can easily lead to bugs and vulnerabilities
|
||||
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
while (*s1 && *s2) {
|
||||
if (*s1 != *s2)
|
||||
break;
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return *(unsigned char *)s1 - *(unsigned char *)s2;
|
||||
}
|
||||
|
Reference in New Issue
Block a user