源代码
sds sdsgrowzero(sds s,size_t len){ struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); size_t totlen,curlen = sh->len; if(len <= curlen) return s; s = sdsMakeRoomFor(s,len-curlen); if(s = NULL) return NULL; /*Make sure added region doesn't contain garbage*/ sh = (void*)(s-(sizeof(struct sdshdr))); memset(s+curlen,0,(len-curlen+1));//also set trailing \0 byte totlen = sh->len+sh->free; sh->len = len; sh->free = totlen-sh->len; return s;}
函数功能
将sds字符串的长度指定为len,不是原来字符串长度部分的sds将被统一设置为0.