summaryrefslogtreecommitdiffstats
path: root/djgpp/unsetenv.c
blob: f00c5d0739468b70b8c350ac0daaedaa4f5e1708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
   libc of DJGPP 2.03 does not offer function unsetenv,
   so this version from DJGPP 2.04 CVS tree is supplied.
   This file will become superflous and will be removed
   from the  distribution as soon as DJGPP 2.04 has been
   released.
*/

/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */

#include <libc/stubs.h>
#include <libc/unconst.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>

extern char **environ;

int
unsetenv(const char *name)
{
  /* 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
   * Note that we can just pass name directly as our putenv() treats
   * this the same as passing 'name='. */
  /* The cast is needed because POSIX specifies putenv() to take a non-const
   * parameter.  Our putenv is well-behaved, so this is OK.  */
  putenv (unconst (name, char*));

  return 0;
}