summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/src/util.c b/src/util.c
index 29bf755f8..b46a2a15c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * 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 <git2.h>
#include "common.h"
#include <stdarg.h>
@@ -118,9 +124,9 @@ Return:
return GIT_SUCCESS;
}
-void git__strntolower(char *str, int len)
+void git__strntolower(char *str, size_t len)
{
- int i;
+ size_t i;
for (i = 0; i < len; ++i) {
str[i] = (char) tolower(str[i]);
@@ -208,7 +214,7 @@ void git__hexdump(const char *buffer, size_t len)
printf("%02X ", (unsigned char)*line & 0xFF);
for (j = 0; j < (LINE_WIDTH - last_line); ++j)
- printf(" ");
+ printf(" ");
printf("| ");
@@ -249,7 +255,7 @@ uint32_t git__hash(const void *key, int len, unsigned int seed)
case 3: h ^= data[2] << 16;
case 2: h ^= data[1] << 8;
case 1: h ^= data[0];
- h *= m;
+ h *= m;
};
h ^= h >> 13;
@@ -270,13 +276,13 @@ uint32_t git__hash(const void *key, int len, uint32_t seed)
{
#define MURMUR_BLOCK() {\
- k1 *= c1; \
- k1 = git__rotl(k1,11);\
- k1 *= c2;\
- h1 ^= k1;\
- h1 = h1*3 + 0x52dce729;\
- c1 = c1*5 + 0x7b7d159c;\
- c2 = c2*5 + 0x6bce6396;\
+ k1 *= c1; \
+ k1 = git__rotl(k1,11);\
+ k1 *= c2;\
+ h1 ^= k1;\
+ h1 = h1*3 + 0x52dce729;\
+ c1 = c1*5 + 0x7b7d159c;\
+ c2 = c2*5 + 0x6bce6396;\
}
const uint8_t *data = (const uint8_t*)key;
@@ -326,20 +332,20 @@ uint32_t git__hash(const void *key, int len, uint32_t seed)
*/
void **git__bsearch(const void *key, void **base, size_t nmemb, int (*compar)(const void *, const void *))
{
- int lim, cmp;
- void **p;
-
- for (lim = nmemb; lim != 0; lim >>= 1) {
- p = base + (lim >> 1);
- cmp = (*compar)(key, *p);
- if (cmp > 0) { /* key > p: move right */
- base = p + 1;
- lim--;
- } else if (cmp == 0) {
- return (void **)p;
- } /* else move left */
- }
- return NULL;
+ int lim, cmp;
+ void **p;
+
+ for (lim = nmemb; lim != 0; lim >>= 1) {
+ p = base + (lim >> 1);
+ cmp = (*compar)(key, *p);
+ if (cmp > 0) { /* key > p: move right */
+ base = p + 1;
+ lim--;
+ } else if (cmp == 0) {
+ return (void **)p;
+ } /* else move left */
+ }
+ return NULL;
}
/**