From: "Tim Van Holder" To: "DJGPP-Workers" Subject: (un)setenv() Date: Tue, 12 Jun 2001 21:34:15 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Reply-To: djgpp-workers AT delorie DOT com I've written a simple implementation of unsetenv(), as that's part of the new Posix standard. That standard also specifies setenv(), though with slightly different semantics (specifies errno=EINVAL if the name contains a '='). Okay to update this function and its docs to match the spec and move it from src/libc/compat/v1 to src/libc/posix/stdlib? ** unsetenv.c /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */ #include #include #include extern char **environ; int unsetenv(const char *name) { char *name_with_equal_sign = NULL; /* No environment == success */ if (environ == 0) return 0; /* Check for the failure conditions */ if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) { errno = EINVAL; return -1; } /* Let putenv() do the work */ name_with_assign = malloc (strlen (name) + 2); strcpy (name_with_assign, name); strcat (name_with_assign, "="); putenv (name_with_assign); free (name_with_assign); return 0; } ** unsetenv.txh @node unsetenv, environment @subheading Syntax @example #include int unsetenv(const char *name); @end example @subheading Description This function removes the environment variable @var{name} from the environment. This will update the list of pointers to which the @var{environ} variable points. If the specified variable does not exist in the environment, the environment is not modified and this function is considered to have been sucessfully completed. @subheading Return Value If @var{name} is @code{NULL}, points to an empty string, or points to a string containing a @samp{=}, this function returns -1 and sets @var{errno} to @code{EINVAL}; otherwise it returns 0. @subheading Portability @portability !ansi, posix @port-note Posix 1003.1-200x, not POSIX-1:1996