Sha256: f93c5ba3498ac04d98ba13d3a320263892452356f797c4091411e5833dfe82f2

Contents?: true

Size: 1.03 KB

Versions: 39

Compression:

Stored size: 1.03 KB

Contents

/*
 * Copyright (C) the libgit2 contributors. All rights reserved.
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */

#include "varint.h"

uintmax_t git_decode_varint(const unsigned char *bufp, size_t *varint_len)
{
	const unsigned char *buf = bufp;
	unsigned char c = *buf++;
	uintmax_t val = c & 127;
	while (c & 128) {
		val += 1;
		if (!val || MSB(val, 7)) {
			/* This is not a valid varint_len, so it signals
			   the error */
			*varint_len = 0;
			return 0; /* overflow */
		}
		c = *buf++;
		val = (val << 7) + (c & 127);
	}
	*varint_len = buf - bufp;
	return val;
}

int git_encode_varint(unsigned char *buf, size_t bufsize, uintmax_t value)
{
	unsigned char varint[16];
	unsigned pos = sizeof(varint) - 1;
	varint[pos] = value & 127;
	while (value >>= 7)
		varint[--pos] = 128 | (--value & 127);
	if (buf) {
		if (bufsize < (sizeof(varint) - pos))
			return -1;
		memcpy(buf, varint + pos, sizeof(varint) - pos);
	}
	return sizeof(varint) - pos;
}

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
rugged-1.7.2 vendor/libgit2/src/util/varint.c
rugged-1.6.5 vendor/libgit2/src/util/varint.c
rugged-1.7.1 vendor/libgit2/src/util/varint.c
rugged-1.6.3 vendor/libgit2/src/util/varint.c
rugged-1.6.2 vendor/libgit2/src/util/varint.c
rugged-1.5.1 vendor/libgit2/src/util/varint.c
rugged-1.4.5 vendor/libgit2/src/varint.c
rugged-1.5.0.1 vendor/libgit2/src/util/varint.c
rugged-1.5.0 vendor/libgit2/src/util/varint.c
rugged-1.3.2.3 vendor/libgit2/src/varint.c
rugged-1.4.4 vendor/libgit2/src/varint.c
rugged-1.3.2.1 vendor/libgit2/src/varint.c
rugged-1.4.3 vendor/libgit2/src/varint.c
rugged-1.3.2 vendor/libgit2/src/varint.c
rugged-1.4.2 vendor/libgit2/src/varint.c
rugged-1.3.1 vendor/libgit2/src/varint.c
rugged-1.3.0 vendor/libgit2/src/varint.c
rugged-1.2.0 vendor/libgit2/src/varint.c
rugged-1.1.1 vendor/libgit2/src/varint.c
rugged-1.1.0 vendor/libgit2/src/varint.c