added solaris 10 support

Mon, 23 Jul 2012 15:13:19 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 23 Jul 2012 15:13:19 +0200
changeset 32
ebba53de8b18
parent 31
280250e45ba6
child 34
2b4574e617c0

added solaris 10 support

src/server/Makefile file | annotate | diff | comparison | revisions
src/server/daemon/log.c file | annotate | diff | comparison | revisions
src/server/daemon/webserver.c file | annotate | diff | comparison | revisions
src/server/util/io.c file | annotate | diff | comparison | revisions
src/server/util/io.h file | annotate | diff | comparison | revisions
--- a/src/server/Makefile	Fri May 25 18:16:24 2012 +0200
+++ b/src/server/Makefile	Mon Jul 23 15:13:19 2012 +0200
@@ -29,7 +29,7 @@
 BUILD_ROOT = ../../
 include $(BUILD_ROOT)conf.mk
 
-CFLAGS  =
+CFLAGS  = -xc99
 
 LDFLAGS = -pg -L/usr/lib/mps -R/usr/lib/mps -lplds4 -lplc4 -lnspr4 -lpthread -ldl -lposix4  -lsocket -lnsl -lgen -lm -lsendfile -lxerces-c
 
--- a/src/server/daemon/log.c	Fri May 25 18:16:24 2012 +0200
+++ b/src/server/daemon/log.c	Mon Jul 23 15:13:19 2012 +0200
@@ -35,6 +35,7 @@
 
 #include "log.h"
 #include "../util/strbuf.h"
+#include "../util/io.h"
 
 int is_initialized = 0;
 
--- a/src/server/daemon/webserver.c	Fri May 25 18:16:24 2012 +0200
+++ b/src/server/daemon/webserver.c	Mon Jul 23 15:13:19 2012 +0200
@@ -32,6 +32,7 @@
 
 #include "../public/nsapi.h"
 #include "../util/systhr.h"
+#include "../util/io.h"
 
 #include "func.h"
 #include "config.h"
--- a/src/server/util/io.c	Fri May 25 18:16:24 2012 +0200
+++ b/src/server/util/io.c	Mon Jul 23 15:13:19 2012 +0200
@@ -30,6 +30,8 @@
 #include <stdlib.h>
 #include <sys/uio.h>
 
+#include <limits.h> /* asprintf */
+
 #include "io.h"
 #include "pool.h"
 
@@ -139,3 +141,103 @@
 ssize_t iovec_buf_flush(iovec_buf_t *io, int fd) {
     return writev(fd, io->iov, io->iovctn);
 }
+
+
+/* TODO: add asprintf to new file */
+
+/* 
+ * asprintf implementation for Solaris 10 
+ * source from OpenSolaris
+ * file: /onnv/onnv-gate/usr/src/lib/libc/port/print/asprintf.c
+ */
+
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 2004 Darren Tucker.
+ *
+ * Based originally on asprintf.c from OpenBSD:
+ * Copyright (c) 1997 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.
+ */
+
+#ifdef __SunOS_5_10
+
+#define	INIT_SZ	128
+
+/* VARARGS2 */
+int
+vasprintf(char **str, const char *format, va_list ap)
+{
+	char string[INIT_SZ];
+	char *newstr;
+	int ret;
+	size_t len;
+
+	*str = NULL;
+	ret = vsnprintf(string, INIT_SZ, format, ap);
+	if (ret < 0)	/* retain the value of errno from vsnprintf() */
+		return (-1);
+	if (ret < INIT_SZ) {
+		len = ret + 1;
+		if ((newstr = malloc(len)) == NULL)
+			return (-1);	/* retain errno from malloc() */
+		(void) strlcpy(newstr, string, len);
+		*str = newstr;
+		return (ret);
+	}
+	/*
+	 * We will perform this loop more than once only if some other
+	 * thread modifies one of the vasprintf() arguments after our
+	 * previous call to vsnprintf().
+	 */
+	for (;;) {
+		if (ret == INT_MAX) {	/* Bad length */
+			errno = ENOMEM;
+			return (-1);
+		}
+		len = ret + 1;
+		if ((newstr = malloc(len)) == NULL)
+			return (-1);	/* retain errno from malloc() */
+		ret = vsnprintf(newstr, len, format, ap);
+		if (ret < 0) {		/* retain errno from vsnprintf() */
+			free(newstr);
+			return (-1);
+		}
+		if (ret < len) {
+			*str = newstr;
+			return (ret);
+		}
+		free(newstr);
+	}
+}
+
+int
+asprintf(char **str, const char *format, ...)
+{
+	va_list ap;
+	int ret;
+
+	*str = NULL;
+	va_start(ap, format);
+	ret = vasprintf(str, format, ap);
+	va_end(ap);
+
+	return (ret);
+}
+
+#endif
--- a/src/server/util/io.h	Fri May 25 18:16:24 2012 +0200
+++ b/src/server/util/io.h	Mon Jul 23 15:13:19 2012 +0200
@@ -90,6 +90,14 @@
 ssize_t iovec_buf_flush(iovec_buf_t *io, int fd);
 
 
+
+#ifdef __SunOS_5_10
+
+int vasprintf(char **str, const char *format, va_list ap);
+int asprintf(char **str, const char *format, ...);
+
+#endif
+
 #ifdef	__cplusplus
 }
 #endif

mercurial