X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/e19206c2bfbd24ae9eceb5fbba9324fdcb3a544f..ad61a8f85b8e2dc5b3bbfe0629480e635af8bd3f:/env.c diff --git a/env.c b/env.c index 4a4fbe5..985dc52 100644 --- a/env.c +++ b/env.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: env.c,v 1.1 1999/07/26 23:15:57 mdw Exp $ + * $Id: env.c,v 1.4 2001/01/25 21:14:26 mdw Exp $ * * Fiddling with environment variables * @@ -30,6 +30,16 @@ /*----- Revision history --------------------------------------------------* * * $Log: env.c,v $ + * Revision 1.4 2001/01/25 21:14:26 mdw + * Nowadays, @SYM_LEN@ doesn't include the terminating null, so revise the + * buffer-usage calculation. + * + * Revision 1.3 2001/01/20 11:48:10 mdw + * Use new @SYM_LEN@ macro for name lengths. + * + * Revision 1.2 2000/06/17 10:39:00 mdw + * Add support for arena management. + * * Revision 1.1 1999/07/26 23:15:57 mdw * Fiddling with environment variables. * @@ -97,7 +107,7 @@ void env_put(sym_table *t, const char *name, const char *value) { size_t eq = strcspn(name, "="); if (name[eq] == '=') { - q = xmalloc(eq + 1); + q = x_alloc(t->t.a, eq + 1); memcpy(q, name, eq); q[eq] = 0; value = name + eq + 1; @@ -110,21 +120,21 @@ void env_put(sym_table *t, const char *name, const char *value) if (!value) { var *v; if ((v = sym_find(t, name, -1, 0, 0)) != 0) { - free(v->v); + x_free(t->t.a, v->v); sym_remove(t, v); } } else { unsigned found; var *v = sym_find(t, name, -1, sizeof(*v), &found); if (found) - free(v->v); - v->v = xstrdup(value); + x_free(t->t.a, v->v); + v->v = x_strdup(t->t.a, value); } /* --- Tidying --- */ if (q) - free(q); + xfree(q); } /* --- @env_import@ --- * @@ -171,7 +181,7 @@ char **env_export(sym_table *t) for (sym_mkiter(&i, t); (v = sym_next(&i)) != 0; ) { n++; - sz += strlen(SYM_NAME(v)) + strlen(v->v) + 2; + sz += SYM_LEN(v) + strlen(v->v) + 2; } /* --- Allocate the big chunk of memory --- */ @@ -209,7 +219,7 @@ void env_destroy(sym_table *t) var *v; for (sym_mkiter(&i, t); (v = sym_next(&i)) != 0; ) - free(v->v); + x_free(t->t.a, v->v); sym_destroy(t); }