Compare commits
5 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c23dc5653 | ||
|
|
9d83fd1975 | ||
|
|
aca1107418 | ||
|
|
41cb395b0d | ||
|
|
08a1c588c3 |
3 changed files with 77 additions and 8 deletions
29
APKBUILD
Normal file
29
APKBUILD
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Maintainer: Imbus <imbus64@protonmail.com>
|
||||||
|
pkgname=libhash
|
||||||
|
pkgver=0.1.2
|
||||||
|
pkgrel=0
|
||||||
|
pkgdesc="Various hash functions in C"
|
||||||
|
url="https://git.silversoft.se/Imbus/libhash"
|
||||||
|
arch="all"
|
||||||
|
license="MIT"
|
||||||
|
makedepends="gcc make"
|
||||||
|
checkdepends=""
|
||||||
|
subpackages="$pkgname-static $pkgname-dev"
|
||||||
|
source="$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz"
|
||||||
|
builddir="$srcdir/$pkgname"
|
||||||
|
|
||||||
|
build() {
|
||||||
|
make
|
||||||
|
}
|
||||||
|
|
||||||
|
check() {
|
||||||
|
make test
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
PREFIX="$pkgdir/usr" make install
|
||||||
|
}
|
||||||
|
|
||||||
|
sha512sums="
|
||||||
|
2e7d02e96f26569a2ae2e29d8644fa93e08229fbb288a67418c986d928cfa3d93e16793ca20cc9a39cbc74e5842395a37923f843fba2215350db350a307ff080 libhash-0.1.2.tar.gz
|
||||||
|
"
|
||||||
25
Makefile
25
Makefile
|
|
@ -1,5 +1,5 @@
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
CFLAGS ?= -Wall -fPIC -Ihash -O2
|
CFLAGS ?= -Wall -Wextra -fPIC -Ihash -O2
|
||||||
AR ?= ar
|
AR ?= ar
|
||||||
ARFLAGS ?= rcs
|
ARFLAGS ?= rcs
|
||||||
|
|
||||||
|
|
@ -13,7 +13,12 @@ PREFIX ?= /usr/local
|
||||||
INCLUDEDIR = $(PREFIX)/include
|
INCLUDEDIR = $(PREFIX)/include
|
||||||
LIBDIR = $(PREFIX)/lib
|
LIBDIR = $(PREFIX)/lib
|
||||||
|
|
||||||
all: $(STATIC_LIB) $(SHARED_LIB)
|
TEST_SRC = test.c
|
||||||
|
TEST_BIN = test.elf
|
||||||
|
|
||||||
|
all: $(STATIC_LIB) $(SHARED_LIB) $(TEST_BIN)
|
||||||
|
test: $(TEST_BIN)
|
||||||
|
./$<
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
@ -24,11 +29,15 @@ $(STATIC_LIB): $(OBJS)
|
||||||
$(SHARED_LIB): $(OBJS)
|
$(SHARED_LIB): $(OBJS)
|
||||||
$(CC) -shared -o $@ $^
|
$(CC) -shared -o $@ $^
|
||||||
|
|
||||||
|
$(TEST_BIN): $(TEST_SRC) $(STATIC_LIB)
|
||||||
|
$(CC) -Wall -Ihash -o $@ $(TEST_SRC) $(STATIC_LIB)
|
||||||
|
|
||||||
install: $(STATIC_LIB) $(SHARED_LIB)
|
install: $(STATIC_LIB) $(SHARED_LIB)
|
||||||
mkdir -p $(DESTDIR)$(INCLUDEDIR)/hash
|
install -d $(DESTDIR)$(INCLUDEDIR)/hash
|
||||||
cp -r hash/*.h $(DESTDIR)$(INCLUDEDIR)/hash/
|
install -m 644 hash/*.h $(DESTDIR)$(INCLUDEDIR)/hash/
|
||||||
mkdir -p $(DESTDIR)$(LIBDIR)
|
install -d $(DESTDIR)$(LIBDIR)
|
||||||
cp $(STATIC_LIB) $(SHARED_LIB) $(DESTDIR)$(LIBDIR)/
|
install -m 644 $(STATIC_LIB) $(DESTDIR)$(LIBDIR)/
|
||||||
|
install -m 755 $(SHARED_LIB) $(DESTDIR)$(LIBDIR)/
|
||||||
@echo "Installed libraries to $(DESTDIR)$(LIBDIR) and headers to $(DESTDIR)$(INCLUDEDIR)/hash"
|
@echo "Installed libraries to $(DESTDIR)$(LIBDIR) and headers to $(DESTDIR)$(INCLUDEDIR)/hash"
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
|
|
@ -37,6 +46,6 @@ uninstall:
|
||||||
@echo "Uninstalled libraries from $(DESTDIR)$(LIBDIR) and headers from $(DESTDIR)$(INCLUDEDIR)/hash"
|
@echo "Uninstalled libraries from $(DESTDIR)$(LIBDIR) and headers from $(DESTDIR)$(INCLUDEDIR)/hash"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS) $(STATIC_LIB) $(SHARED_LIB)
|
rm -f $(OBJS) $(STATIC_LIB) $(SHARED_LIB) $(TEST_BIN)
|
||||||
|
|
||||||
.PHONY: all clean install uninstall
|
.PHONY: all clean install uninstall test
|
||||||
|
|
|
||||||
31
test.c
Normal file
31
test.c
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
#include "hash/crc32.h"
|
||||||
|
#include "hash/djb2.h"
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
assert(crc32("123456789", 9) == 0xCBF43926);
|
||||||
|
assert(crc32("", 0) == 0x00000000);
|
||||||
|
assert(crc32("a", 1) == 0xE8B7BE43);
|
||||||
|
assert(crc32("A", 1) == 0xD3D99E8B);
|
||||||
|
assert(crc32("hello", 5) == 0x3610A686);
|
||||||
|
assert(crc32("The quick brown fox jumps over the lazy dog", 43) == 0x414FA339);
|
||||||
|
assert(crc32("The quick brown fox jumps over the lazy dog.", 44) == 0x519025E9);
|
||||||
|
|
||||||
|
/* Keep in mind the update api requires initialization and finalization */
|
||||||
|
uint32_t crc = crc32_init();
|
||||||
|
crc = crc32_update_raw(crc, "a", 1);
|
||||||
|
crc = crc32_finalize(crc);
|
||||||
|
|
||||||
|
assert(crc == crc32("a", 1));
|
||||||
|
assert(crc == 0xE8B7BE43);
|
||||||
|
|
||||||
|
assert(djb2("Hello") == 0x000000310D4F2079);
|
||||||
|
assert(djb2("a") == 0x000000000002B606);
|
||||||
|
assert(djb2("A") == 0x000000000002B5E6);
|
||||||
|
assert(djb2("123456789") == 0x0377821035CDBB82);
|
||||||
|
|
||||||
|
printf("All good!\n");
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue