?? copy.cc
字號:
#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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -