summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile63
-rwxr-xr-xconfigure45
-rw-r--r--test-fgetln.c8
-rw-r--r--test-getsubopt.c13
-rw-r--r--test-mmap.c6
-rw-r--r--test-strlcat.c7
-rw-r--r--test-strlcpy.c7
-rw-r--r--test-strptime.c9
8 files changed, 86 insertions, 72 deletions
diff --git a/Makefile b/Makefile
index 5209ccf9..0dbc0770 100644
--- a/Makefile
+++ b/Makefile
@@ -53,6 +53,14 @@ DBBIN = mandocdb manpage apropos
all: mandoc preconv demandoc $(DBBIN)
+TESTSRCS = test-fgetln.c \
+ test-getsubopt.c \
+ test-mmap.c \
+ test-ohash.c \
+ test-strlcat.c \
+ test-strlcpy.c \
+ test-strptime.c
+
SRCS = Makefile \
NEWS \
TODO \
@@ -147,16 +155,10 @@ SRCS = Makefile \
term.h \
term_ascii.c \
term_ps.c \
- test-fgetln.c \
- test-getsubopt.c \
- test-mmap.c \
- test-ohash.c \
- test-strlcat.c \
- test-strlcpy.c \
- test-strptime.c \
tree.c \
vol.c \
- vol.in
+ vol.in \
+ $(TESTSRCS)
LIBMAN_OBJS = man.o \
man_hash.o \
@@ -357,50 +359,9 @@ mdocml.tar.gz: $(SRCS)
index.html: $(INDEX_OBJS)
-config.h: config.h.pre config.h.post
+config.h: configure config.h.pre config.h.post $(TESTSRCS)
rm -f config.log
- ( cat config.h.pre; \
- echo; \
- echo '#define VERSION "$(VERSION)"'; \
- if $(CC) $(CFLAGS) -Werror -Wno-unused -o test-ohash test-ohash.c >> config.log 2>&1; then \
- echo '#define HAVE_OHASH'; \
- rm test-ohash; \
- fi; \
- if $(CC) $(CFLAGS) -Werror -Wno-unused -o test-fgetln test-fgetln.c >> config.log 2>&1; then \
- echo '#define HAVE_FGETLN'; \
- rm test-fgetln; \
- fi; \
- if $(CC) $(CFLAGS) -Werror -Wno-unused -o test-strptime test-strptime.c >> config.log 2>&1; then \
- echo '#define HAVE_STRPTIME'; \
- rm test-strptime; \
- fi; \
- if $(CC) $(CFLAGS) -Werror -Wno-unused -o test-getsubopt test-getsubopt.c >> config.log 2>&1; then \
- echo '#define HAVE_GETSUBOPT'; \
- rm test-getsubopt; \
- fi; \
- if $(CC) $(CFLAGS) -Werror -Wno-unused -o test-strlcat test-strlcat.c >> config.log 2>&1; then \
- echo '#define HAVE_STRLCAT'; \
- rm test-strlcat; \
- fi; \
- if $(CC) $(CFLAGS) -Werror -Wno-unused -o test-mmap test-mmap.c >> config.log 2>&1; then \
- echo '#define HAVE_MMAP'; \
- rm test-mmap; \
- fi; \
- if $(CC) $(CFLAGS) -Werror -Wno-unused -o test-strlcpy test-strlcpy.c >> config.log 2>&1; then \
- echo '#define HAVE_STRLCPY'; \
- rm test-strlcpy; \
- fi; \
- if $(CC) $(CFLAGS) -Werror -Wno-unused -o test-strcasestr test-strcasestr.c >> config.log 2>&1; then \
- echo '#define HAVE_STRCASESTR'; \
- rm test-strcasestr; \
- fi; \
- if $(CC) $(CFLAGS) -Werror -Wno-unused -o test-strsep test-strsep.c >> config.log 2>&1; then \
- echo '#define HAVE_STRSEP'; \
- rm test-strsep; \
- fi; \
- echo; \
- cat config.h.post \
- ) > $@
+ CC="$(CC)" CFLAGS="$(CFLAGS)" VERSION="$(VERSION)" ./configure
.h.h.html:
highlight -I $< >$@
diff --git a/configure b/configure
new file mode 100755
index 00000000..1d164697
--- /dev/null
+++ b/configure
@@ -0,0 +1,45 @@
+#!/bin/sh
+#
+# Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
+#
+# 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.
+
+set -e
+exec > config.h 2> config.log
+
+CFLAGS="${CFLAGS} -Wno-unused -Werror"
+
+runtest() {
+ echo ${CC} ${CFLAGS} -o test-${1} test-${1}.c 1>&2
+ ${CC} ${CFLAGS} -o "test-${1}" "test-${1}.c" 1>&2 || return 0
+ "./test-${1}" && echo "#define HAVE_${2}" \
+ || echo FAILURE: test-${1} returned $? 1>&2
+ rm "test-${1}"
+}
+
+cat config.h.pre
+echo
+echo "#define VERSION \"${VERSION}\""
+runtest fgetln FGETLN
+runtest getsubopt GETSUBOPT
+runtest mmap MMAP
+runtest ohash OHASH
+runtest strcasestr STRCASESTR
+runtest strlcat STRLCAT
+runtest strlcpy STRLCPY
+runtest strptime STRPTIME
+runtest strsep STRSEP
+echo
+cat config.h.post
+
+exit 0
diff --git a/test-fgetln.c b/test-fgetln.c
index 90869cd8..ac225a17 100644
--- a/test-fgetln.c
+++ b/test-fgetln.c
@@ -1,11 +1,11 @@
+#include <sys/types.h>
#include <stdio.h>
-#include <stdlib.h>
+#include <unistd.h>
int
main(void)
{
- char *cp;
size_t sz;
- cp = fgetln(stdin, &sz);
- return 0;
+ fclose(stdin);
+ return(NULL != fgetln(stdin, &sz));
}
diff --git a/test-getsubopt.c b/test-getsubopt.c
index 25e11246..2da98238 100644
--- a/test-getsubopt.c
+++ b/test-getsubopt.c
@@ -4,9 +4,16 @@
#include <stdlib.h>
+extern char *suboptarg;
+
int
-main(int argc, char **argv)
+main(void)
{
- getsubopt(argv, argv, argv);
- return 0;
+ char buf[] = "k=v";
+ char *options = buf;
+ char token0[] = "k";
+ char *const tokens[] = { token0, NULL };
+ char *value = NULL;
+ return( ! (0 == getsubopt(&options, tokens, &value)
+ && suboptarg == buf && value == buf+2 && options == buf+3));
}
diff --git a/test-mmap.c b/test-mmap.c
index 1e0f9422..7fb2f973 100644
--- a/test-mmap.c
+++ b/test-mmap.c
@@ -2,9 +2,7 @@
#include <sys/mman.h>
int
-main(int argc, char **argv)
+main(void)
{
-
- mmap(0, 0, PROT_READ, MAP_SHARED, -1, 0);
- return 0;
+ return(MAP_FAILED != mmap(NULL, 1, PROT_READ, MAP_SHARED, -1, 0));
}
diff --git a/test-strlcat.c b/test-strlcat.c
index 5d450dd0..b74ce6f4 100644
--- a/test-strlcat.c
+++ b/test-strlcat.c
@@ -1,8 +1,9 @@
#include <string.h>
int
-main(int argc, char **argv)
+main(void)
{
- strlcat(argv[0], argv[1], 10);
- return 0;
+ char buf[3] = "a";
+ return( ! (2 == strlcat(buf, "b", sizeof(buf)) &&
+ 'a' == buf[0] && 'b' == buf[1] && '\0' == buf[2]));
}
diff --git a/test-strlcpy.c b/test-strlcpy.c
index c7d182aa..05fa5094 100644
--- a/test-strlcpy.c
+++ b/test-strlcpy.c
@@ -1,8 +1,9 @@
#include <string.h>
int
-main(int argc, char **argv)
+main(void)
{
- strlcpy(argv[0], argv[1], 10);
- return 0;
+ char buf[2] = "";
+ return( ! (1 == strlcpy(buf, "a", sizeof(buf)) &&
+ 'a' == buf[0] && '\0' == buf[1]));
}
diff --git a/test-strptime.c b/test-strptime.c
index 976e9c80..bedc7758 100644
--- a/test-strptime.c
+++ b/test-strptime.c
@@ -1,13 +1,14 @@
#if defined(__linux__) || defined(__MINT__)
-# define _GNU_SOURCE /* strptime(), getsubopt() */
+# define _GNU_SOURCE /* strptime() */
#endif
#include <time.h>
int
-main(int argc, char **argv)
+main(void)
{
struct tm tm;
- strptime(*argv, "%D", &tm);
- return 0;
+ const char input[] = "2014-01-04";
+ return( ! (input+10 == strptime(input, "%Y-%m-%d", &tm) &&
+ 114 == tm.tm_year && 0 == tm.tm_mon && 4 == tm.tm_mday));
}