hysteria

ii wrapper script
git clone git://git.2f30.org/hysteria
Log | Files | Refs | README | LICENSE

commit eba4984afadb8ef76d964f55e491e5dfedd2255d
parent 1be1baf77e139e954d60841ed378b8ffdcce8dad
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  9 Nov 2014 19:06:33 +0000

forgot to add strlcpy, built as util

Diffstat:
MMakefile | 42+++++++++++++++++++++++++-----------------
Mconfig.mk | 1+
Mhysteria-highlight.c | 2+-
Autil.h | 5+++++
Autil/strlcpy.c | 33+++++++++++++++++++++++++++++++++
5 files changed, 65 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,10 +1,19 @@ include config.mk SRC = hysteria-highlight.c hysteria-namelist.c -HDR = arg.h config.def.h -OBJ = ${SRC:.c=.o} +BIN = $(SRC:.c=) +HDR = arg.h config.def.h util.h +LIB = util/strlcpy.o +OBJ = ${SRC:.c=.o} ${LIB} -all: options hysteria-highlight hysteria-namelist +all: options binlib hysteria-highlight hysteria-namelist + +binlib: util.a + $(MAKE) bin + +bin: $(BIN) + +${OBJ}: config.mk util.h config.h options: @echo hysteria build options: @@ -12,27 +21,22 @@ options: @echo "LDFLAGS = ${LDFLAGS}" @echo "CC = ${CC}" +.o: + @echo LD $@ + @$(LD) -o $@ $< util.a $(LDFLAGS) + .c.o: @echo CC $< - @${CC} -c -o $@ $< ${CFLAGS} - -${OBJ}: config.mk config.h + @$(CC) -c -o $@ $< $(CFLAGS) config.h: @echo creating $@ from config.def.h @cp config.def.h $@ -hysteria-highlight: ${OBJ} - @echo CC -o $@ - @${CC} -o $@ $@.o ${LDFLAGS} - -hysteria-namelist: ${OBJ} - @echo CC -o $@ - @${CC} -o $@ $@.o ${LDFLAGS} - -clean: - @echo cleaning - @rm -f hysteria-highlight hysteria-namelist ${OBJ} +util.a: $(LIB) + @echo AR $@ + @$(AR) -r -c $@ $? + @ranlib $@ install: all mkdir -p ${DESTDIR}${PREFIX}/bin @@ -64,4 +68,8 @@ uninstall: ${DESTDIR}${PREFIX}/bin/hysteria-namelist \ ${DESTDIR}${PREFIX}/bin/hysteria-waitfile +clean: + @echo cleaning + @rm -f ${BIN} ${LIB} util.a ${OBJ} + .PHONY: all hysteria options clean dist install uninstall diff --git a/config.mk b/config.mk @@ -23,3 +23,4 @@ LDFLAGS = -s ${LIBS} # compiler and linker CC = cc +LD = $(CC) diff --git a/hysteria-highlight.c b/hysteria-highlight.c @@ -21,9 +21,9 @@ #include <time.h> #include "config.h" - #include "arg.h" char *argv0; +#include "util.h" static char timebuf[TIMEFORMAT_BUFSIZ] = ""; static regex_t nick, nickalign, server, timestamp, ignore, url, word; diff --git a/util.h b/util.h @@ -0,0 +1,5 @@ +/* See LICENSE file for copyright and license details. */ +#include "arg.h" + +#undef strlcpy +size_t strlcpy(char *, const char *, size_t); diff --git a/util/strlcpy.c b/util/strlcpy.c @@ -0,0 +1,33 @@ +/* Taken from OpenBSD */ +#include <sys/types.h> +#include <string.h> +#include "../util.h" + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0) { + while (--n != 0) { + if ((*d++ = *s++) == '\0') + break; + } + } + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + return(s - src - 1); /* count does not include NUL */ +}