From 3db12e8b236ac8f88db8eb4690d10e4a3b8dbcd4 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 16 Jan 1998 12:13:05 +0000 Subject: Initial revision git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- missing/setenv.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 missing/setenv.c (limited to 'missing/setenv.c') diff --git a/missing/setenv.c b/missing/setenv.c new file mode 100644 index 0000000000..b7b43a674b --- /dev/null +++ b/missing/setenv.c @@ -0,0 +1,77 @@ +/* + * 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