/* * Copyright (c) 1991, Larry Wall * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. */ #include "ruby.h" #ifndef NT extern char **environ; #endif extern char **origenviron; #ifndef NT char *strdup(); #endif static int envix(nam) char *nam; { register int i, len = strlen(nam); for (i = 0; environ[i]; i++) { if (memcmp(environ[i],nam,len) == 0 && environ[i][len] == '=') break; /* memcmp must come first to avoid */ } /* potential SEGV's */ return i; } void setenv(nam,val) char *nam, *val; { register int i=envix(nam); /* where does it go? */ if (environ == origenviron) { /* need we copy environment? */ int j; int max; char **tmpenv; /*SUPPRESS 530*/ for (max = i; environ[max]; max++) ; tmpenv = ALLOC_N(char*, max+2); for (j=0; j