summaryrefslogtreecommitdiff
path: root/pkgtools/libnbcompat
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2007-06-25 21:35:03 +0000
committerjoerg <joerg@pkgsrc.org>2007-06-25 21:35:03 +0000
commitc13f697f19b77a926a7364d625ee3d88def2d5e6 (patch)
tree049fa1deef806912897eadfcfba148143d3a46af /pkgtools/libnbcompat
parent2e2abb6ffbac564c657a685277b19f6f960286c6 (diff)
downloadpkgsrc-c13f697f19b77a926a7364d625ee3d88def2d5e6.tar.gz
Add asprintf implementation based on snprintf.
Add vsnprintf prototype as the function is implemented and used. Add all the macros from NetBSD's sys/queue.h defined for the types implemented. Bump version to libnbcompat-20070622. Tested by dmcmahill@NetBSD.org on Solaris. OK jlam@, agc@
Diffstat (limited to 'pkgtools/libnbcompat')
-rw-r--r--pkgtools/libnbcompat/Makefile4
-rw-r--r--pkgtools/libnbcompat/files/asprintf.c98
-rwxr-xr-xpkgtools/libnbcompat/files/configure21
-rw-r--r--pkgtools/libnbcompat/files/configure.ac6
-rw-r--r--pkgtools/libnbcompat/files/nbcompat/config.h.in3
-rw-r--r--pkgtools/libnbcompat/files/nbcompat/queue.h167
-rw-r--r--pkgtools/libnbcompat/files/nbcompat/stdio.h12
7 files changed, 282 insertions, 29 deletions
diff --git a/pkgtools/libnbcompat/Makefile b/pkgtools/libnbcompat/Makefile
index ee0fbcf54ed..b11514a6b30 100644
--- a/pkgtools/libnbcompat/Makefile
+++ b/pkgtools/libnbcompat/Makefile
@@ -1,11 +1,11 @@
-# $NetBSD: Makefile,v 1.49 2007/05/31 10:18:49 rillig Exp $
+# $NetBSD: Makefile,v 1.50 2007/06/25 21:35:03 joerg Exp $
#
# NOTE: If you update this package, it is *mandatory* that you update
# pkgsrc/pkgtools/libnbcompat/files/README to reflect the actual
# list of tested and supported platforms.
#
-DISTNAME= libnbcompat-20070531
+DISTNAME= libnbcompat-20070622
CATEGORIES= pkgtools devel
MASTER_SITES= # empty
DISTFILES= # empty
diff --git a/pkgtools/libnbcompat/files/asprintf.c b/pkgtools/libnbcompat/files/asprintf.c
new file mode 100644
index 00000000000..7a4e95afde7
--- /dev/null
+++ b/pkgtools/libnbcompat/files/asprintf.c
@@ -0,0 +1,98 @@
+/* $NetBSD: asprintf.c,v 1.1 2007/06/25 21:35:04 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDERS 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 <nbcompat.h>
+#include <nbcompat/stdio.h>
+#include <nbcompat/stdlib.h>
+
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+
+int
+asprintf(char **ret, const char *fmt, ...)
+{
+ va_list ap;
+ int retval;
+
+ va_start(ap, fmt);
+ retval = vasprintf(ret, fmt, ap);
+ va_end(ap);
+
+ return retval;
+}
+
+int
+vasprintf(char **ret, const char *fmt, va_list ap)
+{
+ char *buf, *new_buf;
+ size_t len;
+ int retval;
+
+ len = 128;
+ buf = malloc(len);
+ if (buf == NULL) {
+ *ret = NULL;
+ return -1;
+ }
+
+ retval = vsnprintf(buf, len, fmt, ap);
+ if (retval < 0) {
+ free(buf);
+ *ret = NULL;
+ return -1;
+ }
+
+ if (retval < len) {
+ new_buf = realloc(buf, retval + 1);
+ if (new_buf == NULL)
+ *ret = buf;
+ else
+ *ret = new_buf;
+ return retval;
+ }
+
+ len = (size_t)retval + 1;
+ new_buf = realloc(buf, len);
+ if (new_buf == NULL) {
+ free(buf);
+ *ret = NULL;
+ return -1;
+ }
+ retval = vsnprintf(buf, len, fmt, ap);
+ if (retval != len - 1) {
+ free(new_buf);
+ *ret = NULL;
+ return -1;
+ }
+ *ret = new_buf;
+ return retval;
+}
diff --git a/pkgtools/libnbcompat/files/configure b/pkgtools/libnbcompat/files/configure
index cf879289f62..989efed530c 100755
--- a/pkgtools/libnbcompat/files/configure
+++ b/pkgtools/libnbcompat/files/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for libnbcompat 20040911.
+# Generated by GNU Autoconf 2.61 for libnbcompat 20070622.
#
# Report bugs to <grant@NetBSD.org>.
#
@@ -574,8 +574,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME='libnbcompat'
PACKAGE_TARNAME='libnbcompat'
-PACKAGE_VERSION='20040911'
-PACKAGE_STRING='libnbcompat 20040911'
+PACKAGE_VERSION='20070622'
+PACKAGE_STRING='libnbcompat 20070622'
PACKAGE_BUGREPORT='grant@NetBSD.org'
# Factoring default headers for most tests.
@@ -1195,7 +1195,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures libnbcompat 20040911 to adapt to many kinds of systems.
+\`configure' configures libnbcompat 20070622 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1265,7 +1265,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of libnbcompat 20040911:";;
+ short | recursive ) echo "Configuration of libnbcompat 20070622:";;
esac
cat <<\_ACEOF
@@ -1343,7 +1343,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-libnbcompat configure 20040911
+libnbcompat configure 20070622
generated by GNU Autoconf 2.61
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1357,7 +1357,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by libnbcompat $as_me 20040911, which was
+It was created by libnbcompat $as_me 20070622, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ $0 $@
@@ -8887,7 +8887,8 @@ done
-for ac_func in err fgetln fnmatch fparseln getenv isblank \
+
+for ac_func in asprintf err fgetln fnmatch fparseln getenv isblank \
lchflags lchmod lchown lutimes mkdtemp mkstemp setenv setgroupent \
setpassent setprogname snprintf statvfs strdup strerror strlcat \
strlcpy strmode strsep strtoll unsetenv usleep utimes warn
@@ -11676,7 +11677,7 @@ exec 6>&1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by libnbcompat $as_me 20040911, which was
+This file was extended by libnbcompat $as_me 20070622, which was
generated by GNU Autoconf 2.61. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -11725,7 +11726,7 @@ Report bugs to <bug-autoconf@gnu.org>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
-libnbcompat config.status 20040911
+libnbcompat config.status 20070622
configured by $0, generated by GNU Autoconf 2.61,
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
diff --git a/pkgtools/libnbcompat/files/configure.ac b/pkgtools/libnbcompat/files/configure.ac
index 75a5dbd0dcb..a107996ea85 100644
--- a/pkgtools/libnbcompat/files/configure.ac
+++ b/pkgtools/libnbcompat/files/configure.ac
@@ -1,8 +1,8 @@
-dnl $NetBSD: configure.ac,v 1.54 2007/05/07 21:41:34 joerg Exp $
+dnl $NetBSD: configure.ac,v 1.55 2007/06/25 21:35:05 joerg Exp $
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.52)
-AC_INIT([libnbcompat], [20040911], [grant@NetBSD.org])
+AC_INIT([libnbcompat], [20070622], [grant@NetBSD.org])
AC_CONFIG_HEADER(nbcompat/config.h)
AC_ARG_PROGRAM
@@ -216,7 +216,7 @@ AC_FUNC_MALLOC
AC_FUNC_STRERROR_R
AC_FUNC_VPRINTF
-AC_REPLACE_FUNCS([err fgetln fnmatch fparseln getenv isblank \
+AC_REPLACE_FUNCS([asprintf err fgetln fnmatch fparseln getenv isblank \
lchflags lchmod lchown lutimes mkdtemp mkstemp setenv setgroupent \
setpassent setprogname snprintf statvfs strdup strerror strlcat \
strlcpy strmode strsep strtoll unsetenv usleep utimes warn
diff --git a/pkgtools/libnbcompat/files/nbcompat/config.h.in b/pkgtools/libnbcompat/files/nbcompat/config.h.in
index fd3feba5fe7..caae58b0c1a 100644
--- a/pkgtools/libnbcompat/files/nbcompat/config.h.in
+++ b/pkgtools/libnbcompat/files/nbcompat/config.h.in
@@ -6,6 +6,9 @@
/* Define to 1 if you have the <alloca.h> header file. */
#undef HAVE_ALLOCA_H
+/* Define to 1 if you have the `snprintf' function. */
+#undef HAVE_ASPRINTF
+
/* Define to 1 if you have the <assert.h> header file. */
#undef HAVE_ASSERT_H
diff --git a/pkgtools/libnbcompat/files/nbcompat/queue.h b/pkgtools/libnbcompat/files/nbcompat/queue.h
index fbf9411bf4b..16f7677ffe0 100644
--- a/pkgtools/libnbcompat/files/nbcompat/queue.h
+++ b/pkgtools/libnbcompat/files/nbcompat/queue.h
@@ -1,4 +1,4 @@
-/* $NetBSD: queue.h,v 1.2 2004/08/10 18:47:55 jlam Exp $ */
+/* $NetBSD: queue.h,v 1.3 2007/06/25 21:35:05 joerg Exp $ */
/*
* Copyright (c) 1991, 1993
@@ -66,6 +66,32 @@ struct { \
}
#endif
+#ifndef LIST_INIT
+#define LIST_INIT(head) do { \
+ (head)->lh_first = NULL; \
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef LIST_INSERT_AFTER
+#define LIST_INSERT_AFTER(listelm, elm, field) do { \
+ if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
+ (listelm)->field.le_next->field.le_prev = \
+ &(elm)->field.le_next; \
+ (listelm)->field.le_next = (elm); \
+ (elm)->field.le_prev = &(listelm)->field.le_next; \
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef LIST_INSERT_BEFORE
+#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
+ QUEUEDEBUG_LIST_OP((listelm), field) \
+ (elm)->field.le_prev = (listelm)->field.le_prev; \
+ (elm)->field.le_next = (listelm); \
+ *(listelm)->field.le_prev = (elm); \
+ (listelm)->field.le_prev = &(elm)->field.le_next; \
+} while (/*CONSTCOND*/0)
+#endif
+
#ifndef LIST_INSERT_HEAD
#define LIST_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
@@ -75,12 +101,22 @@ struct { \
} while (/*CONSTCOND*/0)
#endif
-#ifndef LIST_INIT
-#define LIST_INIT(head) do { \
- (head)->lh_first = NULL; \
+#ifndef LIST_REMOVE
+#define LIST_REMOVE(elm, field) do { \
+ if ((elm)->field.le_next != NULL) \
+ (elm)->field.le_next->field.le_prev = \
+ (elm)->field.le_prev; \
+ *(elm)->field.le_prev = (elm)->field.le_next; \
} while (/*CONSTCOND*/0)
#endif
+#ifndef LIST_FOREACH
+#define LIST_FOREACH(var, head, field) \
+ for ((var) = ((head)->lh_first); \
+ (var); \
+ (var) = ((var)->field.le_next))
+#endif
+
#ifndef LIST_EMPTY
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
#endif
@@ -91,6 +127,90 @@ struct { \
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
#endif
+#ifndef SLIST_HEAD
+#define SLIST_HEAD(name, type) \
+struct name { \
+ struct type *slh_first; /* first element */ \
+}
+#endif
+
+#ifndef SLIST_HEAD_INITIALIZER
+#define SLIST_HEAD_INITIALIZER(head) \
+ { NULL }
+#endif
+
+#ifndef SLIST_ENTRY
+#define SLIST_ENTRY(type) \
+struct { \
+ struct type *sle_next; /* next element */ \
+}
+#endif
+
+#ifndef SLIST_INIT
+#define SLIST_INIT(head) do { \
+ (head)->slh_first = NULL; \
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef SLIST_INSERT_AFTER
+#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
+ (elm)->field.sle_next = (slistelm)->field.sle_next; \
+ (slistelm)->field.sle_next = (elm); \
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef SLIST_INSERT_HEAD
+#define SLIST_INSERT_HEAD(head, elm, field) do { \
+ (elm)->field.sle_next = (head)->slh_first; \
+ (head)->slh_first = (elm); \
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef SLIST_REMOVE_HEAD
+#define SLIST_REMOVE_HEAD(head, field) do { \
+ (head)->slh_first = (head)->slh_first->field.sle_next; \
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef SLIST_REMOVE
+#define SLIST_REMOVE(head, elm, type, field) do { \
+ if ((head)->slh_first == (elm)) { \
+ SLIST_REMOVE_HEAD((head), field); \
+ } \
+ else { \
+ struct type *curelm = (head)->slh_first; \
+ while(curelm->field.sle_next != (elm)) \
+ curelm = curelm->field.sle_next; \
+ curelm->field.sle_next = \
+ curelm->field.sle_next->field.sle_next; \
+ } \
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef SLIST_REMOVE_AFTER
+#define SLIST_REMOVE_AFTER(slistelm, field) do { \
+ (slistelm)->field.sle_next = \
+ SLIST_NEXT(SLIST_NEXT((slistelm), field), field); \
+} while (/*CONSTCOND*/0)
+#endif
+
+#ifndef SLIST_FOREACH
+#define SLIST_FOREACH(var, head, field) \
+ for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
+#endif
+
+#ifndef SLIST_EMPTY
+#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
+#endif
+
+#ifndef SLIST_FIRST
+#define SLIST_FIRST(head) ((head)->slh_first)
+#endif
+
+#ifndef SLIST_NEXT
+#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
+#endif
+
#ifndef TAILQ_HEAD
#define TAILQ_HEAD(name, type) \
struct name { \
@@ -140,6 +260,23 @@ struct { \
} while (/*CONSTCOND*/0)
#endif
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
+ (elm)->field.tqe_next->field.tqe_prev = \
+ &(elm)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+ (listelm)->field.tqe_next = (elm); \
+ (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
+} while (/*CONSTCOND*/0)
+
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
+ (elm)->field.tqe_next = (listelm); \
+ *(listelm)->field.tqe_prev = (elm); \
+ (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
+} while (/*CONSTCOND*/0)
+
#ifndef TAILQ_REMOVE
#define TAILQ_REMOVE(head, elm, field) do { \
if (((elm)->field.tqe_next) != NULL) \
@@ -151,10 +288,20 @@ struct { \
} while (/*CONSTCOND*/0)
#endif
-#ifndef TAILQ_HEAD_INITIALIZER
-#define TAILQ_HEAD_INITIALIZER(head) \
- { NULL, &(head).tqh_first }
+#ifndef TAILQ_FOREACH
+#define TAILQ_FOREACH(var, head, field) \
+ for ((var) = ((head)->tqh_first); \
+ (var); \
+ (var) = ((var)->field.tqe_next))
#endif
+
+#ifndef TAILQ_FOREACH_REVERSE
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
+ for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \
+ (var); \
+ (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
+#endif
+
#ifndef TAILQ_EMPTY
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
#endif
@@ -164,11 +311,5 @@ struct { \
#ifndef TAILQ_NEXT
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#endif
-#ifndef TAILQ_FOREACH
-#define TAILQ_FOREACH(var, head, field) \
- for ((var) = ((head)->tqh_first); \
- (var); \
- (var) = ((var)->field.tqe_next))
-#endif
#endif /* !_NBCOMPAT_QUEUE_H */
diff --git a/pkgtools/libnbcompat/files/nbcompat/stdio.h b/pkgtools/libnbcompat/files/nbcompat/stdio.h
index 60d3c0bf7a2..20a1271738a 100644
--- a/pkgtools/libnbcompat/files/nbcompat/stdio.h
+++ b/pkgtools/libnbcompat/files/nbcompat/stdio.h
@@ -1,4 +1,4 @@
-/* $NetBSD: stdio.h,v 1.1 2004/08/10 18:47:55 jlam Exp $ */
+/* $NetBSD: stdio.h,v 1.2 2007/06/25 21:35:06 joerg Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -39,6 +39,10 @@
#ifndef _NBCOMPAT_STDIO_H_
#define _NBCOMPAT_STDIO_H_
+#if HAVE_STDARG_H
+# include <stdarg.h>
+#endif
+
#if HAVE_STDIO_H
# include <stdio.h>
#endif
@@ -61,6 +65,12 @@ char *fgetln(FILE *, size_t *);
#if !HAVE_SNPRINTF
int snprintf(char *, size_t, const char *, ...);
+int vsnprintf(char *, size_t, const char *, va_list);
+#endif
+
+#if !HAVE_ASPRINTF
+int asprintf(char **, const char *, ...);
+int vasprintf(char **, const char *, va_list);
#endif
#endif /* !_NBCOMPAT_STDIO_H_ */