summaryrefslogtreecommitdiffstats
path: root/lib/libstand/environment.c
diff options
context:
space:
mode:
authormsmith <msmith@FreeBSD.org>1998-09-26 01:42:40 +0000
committermsmith <msmith@FreeBSD.org>1998-09-26 01:42:40 +0000
commitea783268e73e47b0c3012339d1e278e7045e2305 (patch)
tree622472325886767e4a3905d55b5180ea188a7e99 /lib/libstand/environment.c
parent73ca5cb35b01711ebbbdbdc1d00d3f320d0a852c (diff)
downloadFreeBSD-src-ea783268e73e47b0c3012339d1e278e7045e2305.zip
FreeBSD-src-ea783268e73e47b0c3012339d1e278e7045e2305.tar.gz
Replace the old and extremely icky Mach/NetBSD allocator with a similarly
compact and much better one donated by Matt Dillon. Implement a simple sbrk() which uses the existing setheap() api. Remove the custom allocator from the UFS code. It wasn't working quite right, and it shouldn't be needed with the new allocator. Fix a serious problem with changing the value of already-existent environment variables. Don't attempt to modify the supposedly-const argument to putenv() Fix an off-by-one sizing error in the zipfs code detected by the new allocator. Submitted by: zmalloc from Matt Dillon <dillon@backplane.com>
Diffstat (limited to 'lib/libstand/environment.c')
-rw-r--r--lib/libstand/environment.c75
1 files changed, 41 insertions, 34 deletions
diff --git a/lib/libstand/environment.c b/lib/libstand/environment.c
index 007b6a2..72a9e06 100644
--- a/lib/libstand/environment.c
+++ b/lib/libstand/environment.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: environment.c,v 1.1.1.1 1998/08/20 08:19:55 msmith Exp $
*
*/
@@ -70,7 +70,6 @@ env_setenv(const char *name, int flags, void *value, ev_sethook_t sethook,
struct env_var *ev, *curr, *last;
if ((ev = env_getenv(name)) != NULL) {
-
/*
* If there's a set hook, let it do the work (unless we are working
* for one already.
@@ -78,12 +77,45 @@ env_setenv(const char *name, int flags, void *value, ev_sethook_t sethook,
if ((ev->ev_sethook != NULL) && !(flags & EV_NOHOOK))
return(ev->ev_sethook(ev, flags, value));
} else {
+
+ /*
+ * New variable; create and sort into list
+ */
ev = malloc(sizeof(struct env_var));
ev->ev_name = strdup(name);
ev->ev_value = NULL;
/* hooks can only be set when the variable is instantiated */
ev->ev_sethook = sethook;
ev->ev_unsethook = unsethook;
+
+ /* Sort into list */
+ ev->ev_prev = NULL;
+ ev->ev_next = NULL;
+ /* Search for the record to insert before */
+ for (last = NULL, curr = environ;
+ curr != NULL;
+ last = curr, curr = curr->ev_next) {
+
+ if (strcmp(ev->ev_name, curr->ev_name) < 0) {
+ if (curr->ev_prev) {
+ curr->ev_prev->ev_next = ev;
+ } else {
+ environ = ev;
+ }
+ ev->ev_next = curr;
+ ev->ev_prev = curr->ev_prev;
+ curr->ev_prev = ev;
+ break;
+ }
+ }
+ if (curr == NULL) {
+ if (last == NULL) {
+ environ = ev;
+ } else {
+ last->ev_next = ev;
+ ev->ev_prev = last;
+ }
+ }
}
/* If there is data in the variable, discard it */
@@ -100,35 +132,6 @@ env_setenv(const char *name, int flags, void *value, ev_sethook_t sethook,
/* Keep the flag components that are relevant */
ev->ev_flags = flags & (EV_DYNAMIC);
- /* Sort into list */
- ev->ev_prev = NULL;
- ev->ev_next = NULL;
-
- /* Search for the record to insert before */
- for (last = NULL, curr = environ;
- curr != NULL;
- last = curr, curr = curr->ev_next) {
-
- if (strcmp(ev->ev_name, curr->ev_name) < 0) {
- if (curr->ev_prev) {
- curr->ev_prev->ev_next = ev;
- } else {
- environ = ev;
- }
- ev->ev_next = curr;
- ev->ev_prev = curr->ev_prev;
- curr->ev_prev = ev;
- break;
- }
- }
- if (curr == NULL) {
- if (last == NULL) {
- environ = ev;
- } else {
- last->ev_next = ev;
- ev->ev_prev = last;
- }
- }
return(0);
}
@@ -158,11 +161,15 @@ setenv(const char *name, char *value, int overwrite)
int
putenv(const char *string)
{
- char *value;
+ char *value, *copy;
+ int result;
- if ((value = strchr(string, '=')) != NULL)
+ copy = strdup(string);
+ if ((value = strchr(copy, '=')) != NULL)
*(value++) = 0;
- return(setenv(string, value, 1));
+ result = setenv(copy, value, 1);
+ free(copy);
+ return(result);
}
int
OpenPOWER on IntegriCloud