diff --git a/.gitignore b/.gitignore index f805e81..cf90bfa 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ # Debug files *.dSYM/ *.su +.depend diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f0cbb1e --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +CC = gcc +RM = rm -f +CFLAGS = -fPIC -g -O2 -std=c99 \ + -Wall -Wextra -pedantic -Werror \ + -Wdeclaration-after-statement \ + -Wno-format-zero-length \ + -Wold-style-definition \ + -Woverflow \ + -Wpointer-arith \ + -Wstrict-prototypes \ + -Wunused \ + -Wvla + +LDFLAGS = -g -shared +LDLIBS = + +TARGET_LIB = mulithash.so + +SRCS = errors.c +OBJS = $(subst .c,.o,$(SRCS)) + +all: ${TARGET_LIB} + +$(TARGET_LIB): $(OBJS) + $(CC) ${LDFLAGS} -o $@ $^ + +test: test.o pid.o + $(C) $(LDFLAGS) -o test test.o pid.o $(LDLIBS) + +depend: .depend + +.depend: $(SRCS) + rm -f ./.depend + $(CC) $(CFLAGS) -MM $^>>./.depend; + +clean: + $(RM) $(OBJS) + $(RM) $(TARGET_LIB) + +dist-clean: clean + $(RM) *~ .depend + +.PHONY: all depend clean dist-clean + +include .depend diff --git a/errors.c b/errors.c new file mode 100644 index 0000000..c084b6f --- /dev/null +++ b/errors.c @@ -0,0 +1,18 @@ +/* vim: set ts=8 sw=8 noexpandtab: */ +#include "errors.h" + +static const struct mh_error_desc { + int code; + char *message; +} mh_errordesc[] = { + { MH_E_UNKNOWN_CODE, "unknown multihash code" }, + { MH_E_TOO_SHORT, "multihash too short. must be > 3 bytes" }, + { MH_E_TOO_LONG, "multihash too long. must be < 129 bytes" }, + { MH_E_LEN_NOT_SUPPORTED, "multihash does not yet support" + " digests longer than 127 bytes" } +}; + +const char *mh_error_string(mh_error code) { + code += 1; + return ""; +} diff --git a/errors.h b/errors.h new file mode 100644 index 0000000..8ec5ceb --- /dev/null +++ b/errors.h @@ -0,0 +1,14 @@ +/* vim: set ts=8 sw=8 noexpandtab: */ +#ifndef ERROR_H +#define ERROR_H + +typedef enum { + MH_E_UNKNOWN_CODE = -1, + MH_E_TOO_SHORT = -2, + MH_E_TOO_LONG = -3, + MH_E_LEN_NOT_SUPPORTED = -4 +} mh_error; + +const char *mh_error_string(mh_error code); + +#endif /* end of include guard */