/[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 1452 by msalle, Tue Feb 2 19:09:23 2010 UTC revision 1453 by msalle, Wed Feb 3 21:29:34 2010 UTC
# Line 50  int getvarnamelen(const char *varname) Line 50  int getvarnamelen(const char *varname)
50      pos=strchr(varname,'=');      pos=strchr(varname,'=');
51      if (pos==NULL) /* not var=value */      if (pos==NULL) /* not var=value */
52          return -1;          return -1;
53      return strlen(varname)-strlen(pos); /* no pointer arithmetics */      return (int)strlen(varname)-(int)strlen(pos); /* no pointer arithmetics */
54  }  }
55    
56    
# Line 67  int getvarname(char *varname,const int m Line 67  int getvarname(char *varname,const int m
67          return -1;          return -1;
68      if (varnamelen>maxvarnamelen)      if (varnamelen>maxvarnamelen)
69          return -2;          return -2;
70      strncpy(varname,namevalue,varnamelen);      strncpy(varname,namevalue,(size_t)varnamelen);
71      varname[varnamelen]='\0';      varname[varnamelen]='\0';
72    
73      return 0;      return 0;
# Line 78  int getvarname(char *varname,const int m Line 78  int getvarname(char *varname,const int m
78   * env==NULL) returns -1   * env==NULL) returns -1
79   */   */
80  int getvarindex(const env_t src, const char *varname)   {  int getvarindex(const env_t src, const char *varname)   {
81      int i,len;      int i;
82        size_t len;
83    
84      if (src==NULL || varname==NULL)      if (src==NULL || varname==NULL)
85          return -1;          return -1;
# Line 99  int getvarindex(const env_t src, const c Line 100  int getvarindex(const env_t src, const c
100   * NULL valued src or varname.   * NULL valued src or varname.
101   */   */
102  char *getenv_src(const env_t src, char *varname)        {  char *getenv_src(const env_t src, char *varname)        {
103      int i,len;      int i;
104        size_t len;
105        char *match;
106    
107      /* Don't use getvarindex, since this saves us one strlen (-: */      /* Don't use getvarindex, since this saves us one strlen (-: */
108      if (src==NULL || varname==NULL)      if (src==NULL || varname==NULL)
# Line 108  char *getenv_src(const env_t src, char * Line 111  char *getenv_src(const env_t src, char *
111      len=strlen(varname);      len=strlen(varname);
112      /* Loop over env */      /* Loop over env */
113      for (i=0; src[i]; i++)  {      for (i=0; src[i]; i++)  {
114          if (strncmp(src[i],varname,len)==0 && src[i][len]=='=')          if (strncmp(src[i],varname,len)==0 && src[i][len]=='=') {
115              /* Found match */              /* Found match */
116              return (char *)&(src[i][len+1]);              match=&(src[i][len+1]);
117                return match;
118            }
119      }      }
120      /* NO match found */      /* NO match found */
121      return NULL;      return NULL;
# Line 140  int unsetenvpair(const char *namevalue) Line 145  int unsetenvpair(const char *namevalue)
145   * Returns integer, -1 on error, 0 on success   * Returns integer, -1 on error, 0 on success
146   */   */
147  int clear_env(void)     {  int clear_env(void)     {
148      while(environ[0])      while(environ[0])   {
149          if (unsetenvpair(environ[0]))          if (unsetenvpair(environ[0]))
150              return -1;              return -1;
151        }
152      return 0;      return 0;
153  }  }
154    
# Line 152  int clear_env(void)    { Line 158  int clear_env(void)    {
158   * Returns number of cleaned entries, -1 on error.   * Returns number of cleaned entries, -1 on error.
159   */   */
160  int clear_env_pattern(const char *pattern)      {  int clear_env_pattern(const char *pattern)      {
161      int i=0,match=0,patlen=strlen(pattern),rc;      int i=0,match=0,rc;
162        size_t patlen=strlen(pattern);
163    
164      while(environ[i])   {      while(environ[i])   {
165          if (strncasecmp(pattern,environ[i],patlen)==0)  {          if (strncasecmp(pattern,environ[i],patlen)==0)  {
# Line 390  int add_namevalue(env_t *dst,const char Line 397  int add_namevalue(env_t *dst,const char
397   * unchanged. name and value can be freed by the caller (unlike putenv(3p) )   * unchanged. name and value can be freed by the caller (unlike putenv(3p) )
398   */   */
399  int setenv_dst(env_t *dst,const char *name, const char *value)  {  int setenv_dst(env_t *dst,const char *name, const char *value)  {
400      int i,namelen,valuelen,dstlen;      int i,dstlen;
401        size_t namelen,valuelen;
402      char *namevalue;      char *namevalue;
403      env_t newenv=*dst;      env_t newenv=*dst;
404    
# Line 463  int putenv_src_list(env_t src,const char Line 471  int putenv_src_list(env_t src,const char
471   * free()d.   * free()d.
472   */   */
473  int putenv_src_pattern(env_t src,const char *pattern)   {  int putenv_src_pattern(env_t src,const char *pattern)   {
474      int i,len=strlen(pattern),match=0;      int i,match=0;
475        size_t len=strlen(pattern);
476    
477      /* loop over src environ */      /* loop over src environ */
478      for (i=0; src[i]; i++)  {      for (i=0; src[i]; i++)  {

Legend:
Removed from v.1452  
changed lines
  Added in v.1453

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