/[pdpsoft]/trunk/grid-mw-security/cgul/environ/environ.c
ViewVC logotype

Diff of /trunk/grid-mw-security/cgul/environ/environ.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2086 by msalle, Thu Jul 1 13:46:28 2010 UTC revision 2087 by msalle, Thu Nov 11 15:33:33 2010 UTC
# Line 549  int cgul_setenv_dst(env_t *dst,const cha Line 549  int cgul_setenv_dst(env_t *dst,const cha
549  }  }
550    
551  /**  /**
552     * Removes a variable from dst as in unsetenv() with a 'external environment'.
553     */
554    int cgul_unsetenv_dst(env_t *dst,const char *name)  {
555        int namelen,i;
556        env_t newenv=*dst;
557        int entry=-1;
558    
559        /* Check arguments */
560        if (name==NULL)
561            return -1;
562        namelen=strlen(name);
563    
564        /* look for existing entry */
565        for (i=0; newenv[i]; i++)  {
566            if (strncmp(name,newenv[i],namelen)==0 && newenv[i][namelen]=='=')   {
567                entry=i;
568                break;
569            }
570        }
571        /* no match */
572        if (entry<0) return 0;
573        
574        /* Remainder of list... */
575        for (; newenv[i]; i++);
576    
577        /* Now clean entry if it's there and swap with the last in the list */
578        free(newenv[entry]);
579    
580        /* If there were more than one elements, move the last to the removed one */
581        if (i>0)    {
582            newenv[entry]=newenv[i-1]; /* last element */
583            newenv[i-1]=NULL;
584        } else
585            newenv[entry]=NULL;
586        return 0;
587    }
588    
589    /**
590   * Adds to the current environment the var=value pairs from src which have   * Adds to the current environment the var=value pairs from src which have
591   * varname in list. Returns number of entries added or -1 on error.   * varname in list. Returns number of entries added or -1 on error.
592   * NOTE: we do a strdup before the actual putenv, so even though putenv doesn't   * NOTE: we do a strdup before the actual putenv, so even though putenv doesn't

Legend:
Removed from v.2086  
changed lines
  Added in v.2087

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28