redis_3.0.7_sds.c_sdsgrowzero()

源代碼

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

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息