Revision 19926351bcfaf8d524cbc350c09707018e782609 authored by Jiang Xin on 16 June 2018, 14:05:21 UTC, committed by Jiang Xin on 16 June 2018, 14:05:21 UTC
* 'master' of git://github.com/git-l10n/git-po:
  l10n: vi.po(3608t): Update Vietnamese translation for v2.18.0 round2
  l10n: bg.po: Updated Bulgarian translation (3608t)
  l10n: es.po: Spanish update for v2.18.0 round 2
  l10n: git.pot: v2.18.0 round 2 (144 new, 6 removed)
  l10n: fr.po v2.18 round 1
  l10n: vi(3470t): Updated Vietnamese translation for v2.18.0
  l10n: es.po: Spanish update for v2.18.0 round 1
  l10n: git.pot: v2.18.0 round 1 (108 new, 14 removed)
  l10n: TEAMS: remove inactive de team members
  l10n: de.po: fix typos
  l10n: Update Catalan translation
2 parent s 68372c8 + f448ec1
Raw File
varint.c
#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;
}
back to top