commit 73e444b7d01a959f0034ee32fb0a478ef797d289
parent 31791265cbd54d6158aa81ba37a67b740531ee79
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 21 Nov 2014 22:29:09 +0100
dc: improve build
Diffstat:
9 files changed, 105 insertions(+), 10 deletions(-)
diff --git a/dc/Makefile b/dc/Makefile
@@ -1,6 +1,6 @@
-OBJ = dc.o bcode.o inout.o mem.o stack.o
+OBJ = dc.o bcode.o inout.o mem.o stack.o strlcpy.o reallocarray.o
TARG = dc
-LDLIBS =
+LDLIBS = -lcrypto
all: $(TARG)
diff --git a/dc/bcode.c b/dc/bcode.c
@@ -16,7 +16,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <ssl/ssl.h>
+#include <openssl/ssl.h>
#include <err.h>
#include <limits.h>
#include <signal.h>
diff --git a/dc/bcode.h b/dc/bcode.h
@@ -17,7 +17,7 @@
*/
#include <sys/types.h>
-#include <ssl/bn.h>
+#include <openssl/bn.h>
struct number {
diff --git a/dc/dc.c b/dc/dc.c
@@ -25,11 +25,11 @@
#include "extern.h"
-static __dead void usage(void);
+static void usage(void);
extern char *__progname;
-static __dead void
+static void
usage(void)
{
(void)fprintf(stderr, "usage: %s [-x] [-e expression] [file]\n",
@@ -91,8 +91,10 @@ main(int argc, char *argv[])
err(1, "cannot open file %s", argv[0]);
if (fstat(fileno(file), &st) == -1)
err(1, "%s", argv[0]);
- if (S_ISDIR(st.st_mode))
- errc(1, EISDIR, "%s", argv[0]);
+ if (S_ISDIR(st.st_mode)) {
+ errno = EISDIR;
+ err(1, "%s", argv[0]);
+ }
src_setstream(&src, file);
reset_bmachine(&src);
eval();
diff --git a/dc/inout.c b/dc/inout.c
@@ -16,7 +16,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <ssl/ssl.h>
+#include <openssl/ssl.h>
#include <ctype.h>
#include <err.h>
#include <string.h>
diff --git a/dc/mem.c b/dc/mem.c
@@ -16,7 +16,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <ssl/err.h>
+#include <openssl/err.h>
#include <err.h>
#include <stdlib.h>
diff --git a/dc/reallocarray.c b/dc/reallocarray.c
@@ -0,0 +1,38 @@
+/* $OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $ */
+/*
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
+ *
+ * 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 <sys/types.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/*
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
+ */
+#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4))
+
+void *
+reallocarray(void *optr, size_t nmemb, size_t size)
+{
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ nmemb > 0 && SIZE_MAX / nmemb < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(optr, size * nmemb);
+}
diff --git a/dc/strlcpy.c b/dc/strlcpy.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * 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 <string.h>
+#include <sys/types.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 */
+}
diff --git a/dc/util.h b/dc/util.h
@@ -0,0 +1,7 @@
+#include <sys/stat.h>
+
+#include <stdint.h>
+
+void *reallocarray(void *, size_t, size_t);
+
+size_t strlcpy(char *, const char *, size_t);