copy.cc
来自「一个mips虚拟机非常好代码,使用C++来编写的,希望大家多学学,」· CC 代码 · 共 54 行
CC
54 行
#include <stdarg.h>#include <string.h>#include "error.hh"#include "sulima.hh"// Create a dynamically-allocated copy of the string (s), sort of like BSD// strdup().char *copy(const char *s){ size_t len = strlen(s) + 1; char *ret = new char[len]; memcpy(ret, s, len); return ret;}// A bloated but useful version of the above. Returned a dynamically-// allocated copy of the arguments, concatenated into a single string. The// list of arguments is null-terminated. This function is not particularly// fast, but then again, it does not have to be in order to be useful.char *copy(const char *s0, const char *s1, ...){ va_list ap; size_t len0 = strlen(s0), len = 0; const char *s; // Compute the total length of the strings. va_start(ap, s1); for (s = s1, len = len0; s; s = va_arg(ap, const char *)) len += strlen(s); va_end(ap); // Allocate the memory and return concatenated result. char *ret = new char[len + 1]; memcpy(ret, s0, len0); char *d = ret + len0; va_start(ap, s1); for (s = s1; s; s = va_arg(ap, const char *)) { len = strlen(s); memcpy(d, s, len); d += len; } va_end(ap); *d = '\0'; return ret;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?