diff --git a/Makefile b/Makefile index 261a594e..c3242389 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ EXEC = finit reboot HEADERS = plugin.h svc.h helpers.h queue.h DISTFILES = LICENSE README ChangeLog finit.conf services OBJS = finit.o conf.o helpers.o sig.o svc.o plugin.o -OBJS += strlcpy.o tty.o +OBJS += tty.o SRCS = $(OBJS:.o=.c) DEPS = $(addprefix .,$(SRCS:.c=.d)) diff --git a/helpers.h b/helpers.h index 4e9db2e5..05df4b61 100644 --- a/helpers.h +++ b/helpers.h @@ -91,9 +91,6 @@ int run_interactive (char *cmd, char *fmt, ...); pid_t run_getty (char *cmd, int console); int run_parts (char *dir, char *cmd); -/* strlcpy.c */ -size_t strlcpy(char *dst, const char *src, size_t siz); - #endif /* FINIT_HELPERS_H_ */ /** diff --git a/libite/Makefile b/libite/Makefile index daf0adba..c8afb7ba 100644 --- a/libite/Makefile +++ b/libite/Makefile @@ -27,7 +27,7 @@ include ../common.mk CFLAGS += -fPIC HEADERS = lite.h -OBJS := copyfile.o dir.o fexist.o fisdir.o fmode.o rsync.o +OBJS := copyfile.o dir.o fexist.o fisdir.o fmode.o rsync.o strlcpy.o strlcat.o DEPS := $(addprefix ., $(OBJS:.o=.d)) VER = 0 diff --git a/libite/lite.h b/libite/lite.h index 6842e11d..e08e944d 100644 --- a/libite/lite.h +++ b/libite/lite.h @@ -42,6 +42,12 @@ int copy_filep (FILE *src, FILE *dst); int dir (const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip); int rsync (char *src, char *dst, int delete, int (*filter) (const char *file)); +#ifndef strlcpy +size_t strlcpy (char *dst, const char *src, size_t siz); +#endif +#ifndef strlcat +size_t strlcat (char *dst, const char *src, size_t siz); +#endif static inline int fisslashdir(char *dir) { if (!dir) return 0; diff --git a/libite/strlcat.c b/libite/strlcat.c new file mode 100644 index 00000000..18406f3b --- /dev/null +++ b/libite/strlcat.c @@ -0,0 +1,66 @@ +/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +#ifndef strlcat +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} +#endif + +/** + * Local Variables: + * version-control: t + * c-file-style: "bsd" + * End: + */ + + diff --git a/strlcpy.c b/libite/strlcpy.c similarity index 98% rename from strlcpy.c rename to libite/strlcpy.c index dc36ad73..e20808df 100644 --- a/strlcpy.c +++ b/libite/strlcpy.c @@ -19,6 +19,7 @@ #include #include +#ifndef strlcpy /* * Copy src to string dst of size siz. At most siz-1 characters * will be copied. Always NUL terminates (unless siz == 0). @@ -50,6 +51,8 @@ strlcpy(char *dst, const char *src, size_t siz) return(s - src - 1); /* count does not include NUL */ } +#endif + /** * Local Variables: * version-control: t diff --git a/plugins/initctl.c b/plugins/initctl.c index 714fde54..f5e97dbb 100644 --- a/plugins/initctl.c +++ b/plugins/initctl.c @@ -27,6 +27,7 @@ #include #include #include /* read() */ +#include #include "helpers.h" #include "plugin.h"