commit: d58fb08acd156ebe1596abb968bd7ba1040f2687
parent: baafdd7f3357f17014dc79e7bb174f7654807e10
author: Brian Callahan <dodonpachi-github@mailinator.com>
date: Sun, 24 Sep 2017 11:25:44 -0400
Mac OS X needs stravis().
3 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/GNUmakefile b/GNUmakefile
@@ -37,7 +37,8 @@ GROUP = bin
OBJS += portable/common/reallocarray.o
else ifeq ($(UNAME_S),Darwin)
GROUP = bin
-OBJS += portable/common/reallocarray.o portable/common/strtonum.o
+OBJS += portable/common/reallocarray.o portable/common/strtonum.o \
+ portable/darwin/vis.o
else ifeq ($(findstring CYGWIN,$(UNAME_S)),CYGWIN)
OBJS += portable/common/reallocarray.o portable/linux/setmode.o \
portable/linux/signame.o portable/linux/strlcat.o \
diff --git a/portable/darwin/darwin.h b/portable/darwin/darwin.h
@@ -4,6 +4,7 @@
/* Includes */
#include <sys/param.h>
+#include <sys/time.h>
#include <mach/clock.h>
#include <mach/mach.h>
@@ -45,5 +46,7 @@
} while (0)
/* Functions */
+void *reallocarray(void *, size_t, size_t);
+int stravis(char **, const char *, int);
long long strtonum(const char *numstr, long long minval, long long maxval,
const char **errstrp);
diff --git a/portable/darwin/vis.c b/portable/darwin/vis.c
@@ -0,0 +1,60 @@
+/* $OpenBSD: vis.c,v 1.25 2015/09/13 11:32:51 guenther Exp $ */
+/*-
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <ctype.h>
+#include <limits.h>
+#include <string.h>
+#include <stdlib.h>
+#include <vis.h>
+
+#include "darwin.h"
+
+
+/* Mac OS X is only missing stravis(). */
+int
+stravis(char **outp, const char *src, int flag)
+{
+ char *buf;
+ int len, serrno;
+
+ buf = reallocarray(NULL, 4, strlen(src) + 1);
+ if (buf == NULL)
+ return -1;
+ len = strvis(buf, src, flag);
+ serrno = errno;
+ *outp = realloc(buf, len + 1);
+ if (*outp == NULL) {
+ *outp = buf;
+ errno = serrno;
+ }
+ return (len);
+}