/* -*-c-*-
*
- * $Id: env.c,v 1.1 1999/07/26 23:15:57 mdw Exp $
+ * $Id: env.c,v 1.5 2004/04/08 01:36:11 mdw Exp $
*
* Fiddling with environment variables
*
* (c) 1999 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of the mLib utilities library.
*
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
- *
+ *
* mLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Library General Public
* License along with mLib; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: env.c,v $
- * Revision 1.1 1999/07/26 23:15:57 mdw
- * Fiddling with environment variables.
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include <stdio.h>
{
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;
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@ --- *
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 --- */
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);
}