提交 3ab59330 创建 作者: Austin Clements's avatar Austin Clements

Use standard declarations of string functions

Now they agree between kernel, user, and Linux. (This was motivated by link errors in mtrace caused by disagreements between xv6 kernel and user code, but also seems like the right thing to do.)
上级 6266bd9a
...@@ -215,14 +215,14 @@ int kmemcpy(void*, void*, u64); ...@@ -215,14 +215,14 @@ int kmemcpy(void*, void*, u64);
u64 syscall(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num); u64 syscall(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num);
// string.c // string.c
extern "C" int memcmp(const void*, const void*, u32); extern "C" int memcmp(const void*, const void*, size_t);
void* memmove(void*, const void*, u32); void* memmove(void*, const void*, size_t);
extern "C" void* memset(void*, int, u32); extern "C" void* memset(void*, int, size_t);
extern "C" void* memcpy(void*, const void *, u32); extern "C" void* memcpy(void*, const void *, size_t);
char* safestrcpy(char*, const char*, u32); char* safestrcpy(char*, const char*, size_t);
extern "C" unsigned int strlen(const char*); extern "C" unsigned int strlen(const char*);
int strncmp(const char*, const char*, u32); int strncmp(const char*, const char*, size_t);
char* strncpy(char*, const char*, u32); char* strncpy(char*, const char*, size_t);
int strcmp(const char *p, const char *q); int strcmp(const char *p, const char *q);
// swtch.S // swtch.S
......
...@@ -11,8 +11,8 @@ typedef unsigned long long uint64_t; ...@@ -11,8 +11,8 @@ typedef unsigned long long uint64_t;
typedef __PTRDIFF_TYPE__ intptr_t; typedef __PTRDIFF_TYPE__ intptr_t;
typedef unsigned __PTRDIFF_TYPE__ uintptr_t; typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
void* memcpy(void *dst, const void *src, u32 n); void* memcpy(void *dst, const void *src, size_t n);
char* strncpy(char *s, const char *t, int n); char* strncpy(char *s, const char *t, size_t n);
#define RET_IP() ((unsigned long)__builtin_return_address(0)) #define RET_IP() ((unsigned long)__builtin_return_address(0))
......
...@@ -36,10 +36,10 @@ int setfs(u64 base); ...@@ -36,10 +36,10 @@ int setfs(u64 base);
int stat(char*, struct stat*); int stat(char*, struct stat*);
int fstatat(int dirfd, const char*, struct stat*); int fstatat(int dirfd, const char*, struct stat*);
char* strcpy(char*, const char*); char* strcpy(char*, const char*);
void *memmove(void*, const void*, int); void* memmove(void*, const void*, size_t);
char* strchr(const char*, char c); char* strchr(const char*, char c);
int strcmp(const char*, const char*); int strcmp(const char*, const char*);
int strncmp(const char *p, const char *q, u32 n); int strncmp(const char *p, const char *q, size_t n);
int open(const char*, int); int open(const char*, int);
char* gets(char*, int max); char* gets(char*, int max);
......
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
#include "kernel.hh" #include "kernel.hh"
void* void*
memset(void *dst, int c, u32 n) memset(void *dst, int c, size_t n)
{ {
stosb(dst, c, n); stosb(dst, c, n);
return dst; return dst;
} }
int int
memcmp(const void *v1, const void *v2, u32 n) memcmp(const void *v1, const void *v2, size_t n)
{ {
const u8 *s1, *s2; const u8 *s1, *s2;
...@@ -26,7 +26,7 @@ memcmp(const void *v1, const void *v2, u32 n) ...@@ -26,7 +26,7 @@ memcmp(const void *v1, const void *v2, u32 n)
} }
void* void*
memmove(void *dst, const void *src, u32 n) memmove(void *dst, const void *src, size_t n)
{ {
const char *s; const char *s;
char *d; char *d;
...@@ -47,13 +47,13 @@ memmove(void *dst, const void *src, u32 n) ...@@ -47,13 +47,13 @@ memmove(void *dst, const void *src, u32 n)
// memcpy exists to placate GCC. Use memmove. // memcpy exists to placate GCC. Use memmove.
void* void*
memcpy(void *dst, const void *src, u32 n) memcpy(void *dst, const void *src, size_t n)
{ {
return memmove(dst, src, n); return memmove(dst, src, n);
} }
int int
strncmp(const char *p, const char *q, u32 n) strncmp(const char *p, const char *q, size_t n)
{ {
while(n > 0 && *p && *p == *q) while(n > 0 && *p && *p == *q)
n--, p++, q++; n--, p++, q++;
...@@ -63,7 +63,7 @@ strncmp(const char *p, const char *q, u32 n) ...@@ -63,7 +63,7 @@ strncmp(const char *p, const char *q, u32 n)
} }
char* char*
strncpy(char *s, const char *t, u32 n) strncpy(char *s, const char *t, size_t n)
{ {
char *os; char *os;
...@@ -77,7 +77,7 @@ strncpy(char *s, const char *t, u32 n) ...@@ -77,7 +77,7 @@ strncpy(char *s, const char *t, u32 n)
// Like strncpy but guaranteed to NUL-terminate. // Like strncpy but guaranteed to NUL-terminate.
char* char*
safestrcpy(char *s, const char *t, u32 n) safestrcpy(char *s, const char *t, size_t n)
{ {
char *os; char *os;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "amd64.h" #include "amd64.h"
char* char*
strncpy(char *s, const char *t, int n) strncpy(char *s, const char *t, size_t n)
{ {
int tlen = strlen((char *)t); int tlen = strlen((char *)t);
memmove(s, (char *)t, n > tlen ? tlen : n); memmove(s, (char *)t, n > tlen ? tlen : n);
...@@ -34,7 +34,7 @@ strcmp(const char *p, const char *q) ...@@ -34,7 +34,7 @@ strcmp(const char *p, const char *q)
} }
int int
strncmp(const char *p, const char *q, u32 n) strncmp(const char *p, const char *q, size_t n)
{ {
while(n > 0 && *p && *p == *q) while(n > 0 && *p && *p == *q)
n--, p++, q++; n--, p++, q++;
...@@ -127,13 +127,13 @@ atoi(const char *s) ...@@ -127,13 +127,13 @@ atoi(const char *s)
} }
void* void*
memcpy(void *dst, const void *src, unsigned int n) memcpy(void *dst, const void *src, size_t n)
{ {
return memmove(dst, (void *)src, n); return memmove(dst, (void *)src, n);
} }
void* void*
memmove(void *vdst, const void *vsrc, int n) memmove(void *vdst, const void *vsrc, size_t n)
{ {
const char *src; const char *src;
char *dst; char *dst;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论