redis_3.0.7_sds.c_sdscatlen()

源程序

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的位置。

转载于:https://my.oschina.net/u/1771419/blog/1619627

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值