提交 2a78d8e2 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

realloc, vsnprintf

上级 2bb471ef
#include <stdarg.h>
BEGIN_DECLS BEGIN_DECLS
struct stat; struct stat;
struct ipcmsg; struct ipcmsg;
...@@ -61,6 +63,7 @@ void forkt_setup(u64 pid); ...@@ -61,6 +63,7 @@ void forkt_setup(u64 pid);
void printf(const char*, ...); void printf(const char*, ...);
void fprintf(int, const char*, ...); void fprintf(int, const char*, ...);
void snprintf(char *buf, unsigned int n, const char *fmt, ...); void snprintf(char *buf, unsigned int n, const char *fmt, ...);
void vsnprintf(char *buf, u32 n, const char *fmt, va_list ap);
void die(const char* errstr, ...) __attribute__((noreturn)); void die(const char* errstr, ...) __attribute__((noreturn));
#define assert(c) if (!(c)) { fprintf(2, "%s:%d: ", __FILE__, __LINE__); die("assertion failure"); } #define assert(c) if (!(c)) { fprintf(2, "%s:%d: ", __FILE__, __LINE__); die("assertion failure"); }
......
...@@ -109,3 +109,14 @@ initmalloc(void) ...@@ -109,3 +109,14 @@ initmalloc(void)
{ {
initlock(&lock); initlock(&lock);
} }
extern "C" void* realloc(void* ap, size_t nbytes);
void*
realloc(void* ap, size_t nbytes)
{
Header *bp = (header*) ap - 1;
void* n = malloc(nbytes);
memcpy(n, ap, bp->s.size);
free(ap);
return n;
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论