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.curl