Back to index

nagios-plugins  1.4.16
Defines | Functions
unsetenv.c File Reference
#include <config.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

Go to the source code of this file.

Defines

#define _GL_ARG_NONNULL(params)
#define __set_errno(ev)   ((errno) = (ev))
#define __environ   environ
#define LOCK
#define UNLOCK

Functions

int unsetenv (const char *name)

Define Documentation

#define __environ   environ

Definition at line 35 of file unsetenv.c.

#define __set_errno (   ev)    ((errno) = (ev))

Definition at line 28 of file unsetenv.c.

#define _GL_ARG_NONNULL (   params)

Definition at line 21 of file unsetenv.c.

#define LOCK

Definition at line 45 of file unsetenv.c.

#define UNLOCK

Definition at line 46 of file unsetenv.c.


Function Documentation

int unsetenv ( const char *  name)

Definition at line 57 of file unsetenv.c.

{
  size_t len;
  char **ep;

  if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
    {
      __set_errno (EINVAL);
      return -1;
    }

  len = strlen (name);

  LOCK;

  ep = __environ;
  while (*ep != NULL)
    if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
      {
        /* Found it.  Remove this pointer by moving later ones back.  */
        char **dp = ep;

        do
          dp[0] = dp[1];
        while (*dp++);
        /* Continue the loop in case NAME appears again.  */
      }
    else
      ++ep;

  UNLOCK;

  return 0;
}

Here is the caller graph for this function: