summaryrefslogtreecommitdiff
path: root/devel
diff options
context:
space:
mode:
authortnn <tnn@pkgsrc.org>2007-08-03 21:30:59 +0000
committertnn <tnn@pkgsrc.org>2007-08-03 21:30:59 +0000
commit981dfebbb72efe2198e5b67773db83b84b621eef (patch)
tree9292aab133610ebf50acb92d603c0caddbaa8b66 /devel
parentedf5ec82601b9a07e890f0604c489a952adc4ba8 (diff)
downloadpkgsrc-981dfebbb72efe2198e5b67773db83b84b621eef.tar.gz
Add devel/libsetenv, a library that provides implementations of setenv(3)
and unsetenv(3) for platforms that lack them. This package is modeled after devel/libgetopt and the intended use within pkgsrc is similar.
Diffstat (limited to 'devel')
-rw-r--r--devel/libsetenv/DESCR2
-rw-r--r--devel/libsetenv/Makefile29
-rw-r--r--devel/libsetenv/PLIST3
-rw-r--r--devel/libsetenv/buildlink3.mk19
-rw-r--r--devel/libsetenv/builtin.mk79
-rw-r--r--devel/libsetenv/files/libsetenv.c154
-rw-r--r--devel/libsetenv/files/libsetenv.h4
7 files changed, 290 insertions, 0 deletions
diff --git a/devel/libsetenv/DESCR b/devel/libsetenv/DESCR
new file mode 100644
index 00000000000..787b34caea0
--- /dev/null
+++ b/devel/libsetenv/DESCR
@@ -0,0 +1,2 @@
+libsetenv provides implementations of setenv(3) and unsetenv(3) for
+platforms that lack them.
diff --git a/devel/libsetenv/Makefile b/devel/libsetenv/Makefile
new file mode 100644
index 00000000000..420ecf46100
--- /dev/null
+++ b/devel/libsetenv/Makefile
@@ -0,0 +1,29 @@
+# $NetBSD: Makefile,v 1.1.1.1 2007/08/03 21:30:59 tnn Exp $
+#
+
+DISTNAME= libsetenv-0.1
+CATEGORIES= devel
+MASTER_SITES= # empty
+DISTFILES= # empty
+
+MAINTAINER= tnn@NetBSD.org
+HOMEPAGE= http://www.pkgsrc.org/
+COMMENT= Library that provides setenv(3) and unsetenv(3) implementations
+
+NO_CHECKSUM= yes
+NO_CONFIGURE= yes
+USE_LIBTOOL= yes
+
+do-extract:
+ cp -R ${FILESDIR} ${WRKSRC}
+
+do-build:
+ cd ${WRKSRC} && ${LIBTOOL} --mode=compile ${COMPILE.c} libsetenv.c
+ cd ${WRKSRC} && ${LIBTOOL} --mode=link ${LINK.c} -o libsetenv.la \
+ libsetenv.lo -rpath ${PREFIX}/lib
+
+do-install:
+ ${INSTALL_DATA} ${WRKSRC}/libsetenv.h ${PREFIX}/include/
+ ${LIBTOOL} --mode=install ${INSTALL_LIB} ${WRKSRC}/libsetenv.la ${PREFIX}/lib/
+
+.include "../../mk/bsd.pkg.mk"
diff --git a/devel/libsetenv/PLIST b/devel/libsetenv/PLIST
new file mode 100644
index 00000000000..ace33bc4c36
--- /dev/null
+++ b/devel/libsetenv/PLIST
@@ -0,0 +1,3 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 2007/08/03 21:30:59 tnn Exp $
+include/libsetenv.h
+lib/libsetenv.la
diff --git a/devel/libsetenv/buildlink3.mk b/devel/libsetenv/buildlink3.mk
new file mode 100644
index 00000000000..b76eb935195
--- /dev/null
+++ b/devel/libsetenv/buildlink3.mk
@@ -0,0 +1,19 @@
+# $NetBSD: buildlink3.mk,v 1.1.1.1 2007/08/03 21:30:59 tnn Exp $
+
+BUILDLINK_DEPTH:= ${BUILDLINK_DEPTH}+
+LIBSETENV_BUILDLINK3_MK:= ${LIBSETENV_BUILDLINK3_MK}+
+
+.if ${BUILDLINK_DEPTH} == "+"
+BUILDLINK_DEPENDS+= libsetenv
+.endif
+
+BUILDLINK_PACKAGES:= ${BUILDLINK_PACKAGES:Nlibsetenv}
+BUILDLINK_PACKAGES+= libsetenv
+BUILDLINK_ORDER:= ${BUILDLINK_ORDER} ${BUILDLINK_DEPTH}libsetenv
+
+.if ${LIBSETENV_BUILDLINK3_MK} == "+"
+BUILDLINK_API_DEPENDS.libsetenv+= libsetenv>=0.1
+BUILDLINK_PKGSRCDIR.libsetenv?= ../../devel/libsetenv
+.endif # LIBSETENV_BUILDLINK3_MK
+
+BUILDLINK_DEPTH:= ${BUILDLINK_DEPTH:S/+$//}
diff --git a/devel/libsetenv/builtin.mk b/devel/libsetenv/builtin.mk
new file mode 100644
index 00000000000..c830eddb0bd
--- /dev/null
+++ b/devel/libsetenv/builtin.mk
@@ -0,0 +1,79 @@
+# $NetBSD: builtin.mk,v 1.1.1.1 2007/08/03 21:30:59 tnn Exp $
+#
+
+BUILTIN_PKG:= libsetenv
+
+BUILTIN_FIND_FILES_VAR:= H_STDLIB
+BUILTIN_FIND_FILES.H_STDLIB= /usr/include/stdlib.h
+BUILTIN_FIND_GREP.H_STDLIB= setenv
+
+.include "../../mk/buildlink3/bsd.builtin.mk"
+
+#
+###
+### Determine if there is a built-in implementation of the package and
+### set IS_BUILTIN.<pkg> appropriately ("yes" or "no").
+###
+.if !defined(IS_BUILTIN.libsetenv)
+IS_BUILTIN.libsetenv= no
+. if empty(H_STDLIB:M__nonexistent__)
+IS_BUILTIN.libsetenv= yes
+. endif
+.endif
+MAKEVARS+= IS_BUILTIN.libsetenv
+#
+###
+### If there is a built-in implementation, then set BUILTIN_PKG.<pkg> to
+### a package name to represent the built-in package.
+###
+.if !defined(BUILTIN_PKG.libsetenv) && \
+ !empty(IS_BUILTIN.libsetenv:M[yY][eE][sS])
+BUILTIN_PKG.libsetenv= libsetenv-0.1
+.endif
+MAKEVARS+= BUILTIN_PKG.libsetenv
+#
+###
+### Determine whether we should use the built-in implementation if it
+### exists, and set USE_BUILTIN.<pkg> appropriate ("yes" or "no").
+###
+.if !defined(USE_BUILTIN.libsetenv)
+. if ${PREFER.libsetenv} == "pkgsrc"
+USE_BUILTIN.libsetenv= no
+. else
+USE_BUILTIN.libsetenv= ${IS_BUILTIN.libsetenv}
+. if defined(BUILTIN_PKG.libsetenv) && \
+ !empty(IS_BUILTIN.libsetenv:M[yY][eE][sS])
+USE_BUILTIN.libsetenv= yes
+. for _dep_ in ${BUILDLINK_API_DEPENDS.libsetenv}
+. if !empty(USE_BUILTIN.libsetenv:M[yY][eE][sS])
+USE_BUILTIN.libsetenv!= \
+if ${PKG_ADMIN} pmatch ${_dep_:Q} ${BUILTIN_PKG.libsetenv:Q}; then \
+ ${ECHO} "yes"; \
+else \
+ ${ECHO} "no"; \
+fi
+. endif
+. endfor
+. endif
+. endif
+.endif
+MAKEVARS+= USE_BUILTIN.libsetenv
+#
+###
+### The section below only applies if we are not including this file
+### solely to determine whether a built-in implementation exists.
+###
+CHECK_BUILTIN.libsetenv?= no
+.if !empty(CHECK_BUILTIN.libsetenv:M[nN][oO])
+
+. if !empty(USE_BUILTIN.libsetenv:M[nN][oO])
+_BLTN_LIBSETENV= -lsetenv
+. else
+_BLTN_LIBSETENV= # empty
+. endif
+BUILDLINK_LDADD.libsetenv?= ${_BLTN_LIBSETENV}
+
+CONFIGURE_ENV+= LIBSETENV=${BUILDLINK_LDADD.libsetenv:Q}
+MAKE_ENV+= LIBSETENV=${BUILDLINK_LDADD.libsetenv:Q}
+
+.endif # CHECK_BUILTIN.libsetenv
diff --git a/devel/libsetenv/files/libsetenv.c b/devel/libsetenv/files/libsetenv.c
new file mode 100644
index 00000000000..d6318248668
--- /dev/null
+++ b/devel/libsetenv/files/libsetenv.c
@@ -0,0 +1,154 @@
+/* $NetBSD: libsetenv.c,v 1.1.1.1 2007/08/03 21:30:59 tnn Exp $ */
+
+/*
+ * Copyright (c) 1987, 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+extern char **environ;
+
+/*
+ * __findenv --
+ * Returns pointer to value associated with name, if any, else NULL.
+ * Sets offset to be the offset of the name/value combination in the
+ * environmental array, for use by setenv(3) and unsetenv(3).
+ * Explicitly removes '=' in argument name.
+ *
+ * This routine *should* be a static; don't use it.
+ */
+static char *
+__findenv(const char *name, int *offset)
+{
+ size_t len;
+ const char *np;
+ char **p, *c;
+
+ if (name == NULL || environ == NULL)
+ return NULL;
+ for (np = name; *np && *np != '='; ++np)
+ continue;
+ len = np - name;
+ for (p = environ; (c = *p) != NULL; ++p)
+ if (strncmp(c, name, len) == 0 && c[len] == '=') {
+ *offset = p - environ;
+ return c + len + 1;
+ }
+ return NULL;
+}
+
+/*
+ * setenv --
+ * Set the value of the environmental variable "name" to be
+ * "value". If rewrite is set, replace any current value.
+ */
+int
+setenv(name, value, rewrite)
+ const char *name;
+ const char *value;
+ int rewrite;
+{
+ static char **saveenv; /* copy of previously allocated space */
+ char *c, **newenv;
+ const char *cc;
+ size_t l_value, size;
+ int offset;
+
+ if (*value == '=') /* no `=' in value */
+ ++value;
+ l_value = strlen(value);
+ /* find if already exists */
+ if ((c = __findenv(name, &offset)) != NULL) {
+ if (!rewrite)
+ goto good;
+ if (strlen(c) >= l_value) /* old larger; copy over */
+ goto copy;
+ } else { /* create new slot */
+ size_t cnt;
+
+ for (cnt = 0; environ[cnt]; ++cnt)
+ continue;
+ size = (size_t)(sizeof(char *) * (cnt + 2));
+ if (saveenv == environ) { /* just increase size */
+ if ((newenv = realloc(saveenv, size)) == NULL)
+ goto bad;
+ saveenv = newenv;
+ } else { /* get new space */
+ free(saveenv);
+ if ((saveenv = malloc(size)) == NULL)
+ goto bad;
+ (void)memcpy(saveenv, environ, cnt * sizeof(char *));
+ }
+ environ = saveenv;
+ environ[cnt + 1] = NULL;
+ offset = (int)cnt;
+ }
+ for (cc = name; *cc && *cc != '='; ++cc) /* no `=' in name */
+ continue;
+ size = cc - name;
+ /* name + `=' + value */
+ if ((environ[offset] = malloc(size + l_value + 2)) == NULL)
+ goto bad;
+ c = environ[offset];
+ (void)memcpy(c, name, size);
+ c += size;
+ *c++ = '=';
+copy:
+ (void)memcpy(c, value, l_value + 1);
+good:
+ return 0;
+bad:
+ return -1;
+}
+
+/*
+ * unsetenv(name) --
+ * Delete environmental variable "name".
+ */
+int
+unsetenv(name)
+ const char *name;
+{
+ char **p;
+ int offset;
+
+ if (name == NULL || *name == '\0' || strchr(name, '=') != NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ while (__findenv(name, &offset)) /* if set multiple times */
+ for (p = &environ[offset];; ++p)
+ if (!(*p = *(p + 1)))
+ break;
+
+ return 0;
+}
diff --git a/devel/libsetenv/files/libsetenv.h b/devel/libsetenv/files/libsetenv.h
new file mode 100644
index 00000000000..48583b0c628
--- /dev/null
+++ b/devel/libsetenv/files/libsetenv.h
@@ -0,0 +1,4 @@
+/* $NetBSD: libsetenv.h,v 1.1.1.1 2007/08/03 21:30:59 tnn Exp $ */
+
+int setenv(const char *, const char *, int);
+int unsetenv(const char *);