root/replace/unsetenv.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. unsetenv

   1 /*
   2  * Copyright (C) 2001 Alan Robertson <alanr@unix.sh>
   3  * This software licensed under the GNU LGPL.
   4  *
   5  *
   6  * This library is free software; you can redistribute it and/or
   7  * modify it under the terms of the GNU Lesser General Public
   8  * License as published by the Free Software Foundation; either
   9  * version 2.1 of the License, or (at your option) any later version.
  10  * 
  11  * This library is distributed in the hope that it will be useful,
  12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14  * Lesser General Public License for more details.
  15  * 
  16  * You should have received a copy of the GNU Lesser General Public
  17  * License along with this library; if not, write to the Free Software
  18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  19  *
  20  */
  21 
  22 #include <crm_internal.h>
  23 #include <sys/types.h>
  24 #include <stdio.h>
  25 #include <stdlib.h>
  26 #include <string.h>
  27 
  28 #define __environ       environ
  29 #ifndef HAVE_ENVIRON_DECL
  30 extern char **environ;
  31 #endif
  32 
  33 int
  34 unsetenv(const char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36     const size_t len = strlen(name);
  37     char **ep;
  38 
  39     for (ep = __environ; *ep; ++ep) {
  40         if (!strncmp(*ep, name, len) && (*ep)[len] == '=') {
  41             /* Found it.  */
  42             /* Remove this pointer by moving later ones back.  */
  43             char **dp = ep;
  44 
  45             do
  46                 dp[0] = dp[1];
  47             while (*dp++);
  48             /* Continue the loop in case NAME appears again.  */
  49         }
  50     }
  51     return 0;
  52 }

/* [previous][next][first][last][top][bottom][index][help] */