16 Star 86 Fork 0

Gitee 极速下载 / Git

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/git/git
克隆/下载
varint.c 660 Bytes
一键复制 编辑 原始数据 按行查看 历史
#include "git-compat-util.h"
#include "varint.h"
uintmax_t decode_varint(const unsigned char **bufp)
{
const unsigned char *buf = *bufp;
unsigned char c = *buf++;
uintmax_t val = c & 127;
while (c & 128) {
val += 1;
if (!val || MSB(val, 7))
return 0; /* overflow */
c = *buf++;
val = (val << 7) + (c & 127);
}
*bufp = buf;
return val;
}
int encode_varint(uintmax_t value, unsigned char *buf)
{
unsigned char varint[16];
unsigned pos = sizeof(varint) - 1;
varint[pos] = value & 127;
while (value >>= 7)
varint[--pos] = 128 | (--value & 127);
if (buf)
memcpy(buf, varint + pos, sizeof(varint) - pos);
return sizeof(varint) - pos;
}
C
1
https://gitee.com/mirrors/git.git
git@gitee.com:mirrors/git.git
mirrors
git
Git
master

搜索帮助