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.

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券