sds sdscatlen(sds s, const void *t, size_t len) { struct sdshdr *sh; size_t curlen = sdslen(s); s = sdsMakeRoomFor(s, len);//字符串添加len个长度 if (s == NULL) return NULL; sh = (void*)(s - (sizeof(struct sdshdr))); memcpy(s + curlen, t, len);/* 将指针t指向的字符串指向 s+curlen的位置,长度为len */ sh->len = curlen + len; sh->free = sh->free - len; s[curlen + len] = '\0'; return s; }
Append the specified binary-safe string pointed by 't' of 'len' bytes to the end of the specified sds string 's'. 源程序中的注释说明这里增长的字符串是二进制安全的。可是我并无看出来,之后再说,可能慢慢就懂了。安全
该函数的功能就是在原sds字符串的基础上添加len长度的字符串。新添加的字符串的头指针是t,添加到s的位置。curl