pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/devel/libsetenv Add devel/libsetenv, a library that pr...
details: https://anonhg.NetBSD.org/pkgsrc/rev/d6c925b6076e
branches: trunk
changeset: 531650:d6c925b6076e
user: tnn <tnn%pkgsrc.org@localhost>
date: Fri Aug 03 21:30:59 2007 +0000
description:
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:
devel/libsetenv/DESCR | 2 +
devel/libsetenv/Makefile | 29 +++++++
devel/libsetenv/PLIST | 3 +
devel/libsetenv/buildlink3.mk | 19 ++++
devel/libsetenv/builtin.mk | 79 +++++++++++++++++++
devel/libsetenv/files/libsetenv.c | 154 ++++++++++++++++++++++++++++++++++++++
devel/libsetenv/files/libsetenv.h | 4 +
7 files changed, 290 insertions(+), 0 deletions(-)
diffs (truncated from 318 to 300 lines):
diff -r 243035800082 -r d6c925b6076e devel/libsetenv/DESCR
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/libsetenv/DESCR Fri Aug 03 21:30:59 2007 +0000
@@ -0,0 +1,2 @@
+libsetenv provides implementations of setenv(3) and unsetenv(3) for
+platforms that lack them.
diff -r 243035800082 -r d6c925b6076e devel/libsetenv/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/libsetenv/Makefile Fri Aug 03 21:30:59 2007 +0000
@@ -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@localhost
+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 -r 243035800082 -r d6c925b6076e devel/libsetenv/PLIST
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/libsetenv/PLIST Fri Aug 03 21:30:59 2007 +0000
@@ -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 -r 243035800082 -r d6c925b6076e devel/libsetenv/buildlink3.mk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/libsetenv/buildlink3.mk Fri Aug 03 21:30:59 2007 +0000
@@ -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 -r 243035800082 -r d6c925b6076e devel/libsetenv/builtin.mk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/libsetenv/builtin.mk Fri Aug 03 21:30:59 2007 +0000
@@ -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 -r 243035800082 -r d6c925b6076e devel/libsetenv/files/libsetenv.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/libsetenv/files/libsetenv.c Fri Aug 03 21:30:59 2007 +0000
@@ -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;
Home |
Main Index |
Thread Index |
Old Index