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

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

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

revision 1451 by msalle, Tue Feb 2 02:35:46 2010 UTC revision 1452 by msalle, Tue Feb 2 19:09:23 2010 UTC
# Line 20  Line 20 
20   *      <grid-mw-security@nikhef.nl>       *      <grid-mw-security@nikhef.nl>    
21   */   */
22    
23  #include <unistd.h>  #ifndef _ENVIRON_H_
24    #define _ENVIRON_H_
25    
26    #include <unistd.h>
27  extern char **environ;  extern char **environ;
28    
29    /* Define environment list type: note that we CANNOT initialize it as
30     *  env_t myenv={"..","..",NULL} etc. */
31    typedef char **env_t;
32    
33  #ifndef MAXENVVARNAMELEN  #ifndef MAXENVVARNAMELEN
34  #define MAXENVVARNAMELEN        16384  #define MAXENVVARNAMELEN        16384
35  #endif  #endif
# Line 52  int getvarname(char *varname,const int m Line 58  int getvarname(char *varname,const int m
58   * Finds index in **src matching variable name, in case of no match (including   * Finds index in **src matching variable name, in case of no match (including
59   * env==NULL) returns -1   * env==NULL) returns -1
60   */   */
61  int getvarindex(const char **src, const char *varname);  int getvarindex(const env_t src, const char *varname);
62    
63  /**  /**
64   * Finds the value of varname in src list. Returns NULL when no match, incl.   * Finds the value of varname in src list. Returns NULL when no match, incl.
65   * NULL valued src or varname.   * NULL valued src or varname.
66   */   */
67  char *getenv_src(const char **src, char *varname);  char *getenv_src(const env_t src, char *varname);
68    
69  /**  /**
70   * As unsetenv(3) but using var=value pair, specified in namevalue. The maximum   * As unsetenv(3) but using var=value pair, specified in namevalue. The maximum
# Line 81  int clear_env(void); Line 87  int clear_env(void);
87  int clear_env_pattern(const char *pattern);  int clear_env_pattern(const char *pattern);
88    
89  /**  /**
90   * Returns a duplicate of src. In case dst!=NULL it will be used and should be   * Creates a duplicate of src. In case *dst!=NULL it will be used and should be
91   * big enough. Otherwise space is malloced.   * big enough. Otherwise space is malloc-ed. dst is only updated upon success.
92     * Returns -1 upon error, 0 on success.
93   */   */
94  char **copy_env(char **dst,const char **src);  int copy_env(env_t *dst,const env_t src);
95    
96  /**  /**
97   * Same as copy_env() but first unsets all environment variables starting with   * Same as copy_env() but first unsets all environment variables starting with
98   * MALLOC, case INsensitive.   * MALLOC, case INsensitive. dst is again only updated upon success.
99     * Returns -1 upon error, 0 on success.
100   */   */
101  char **safe_copy_env(char **dst,const char **src);  int safe_copy_env(env_t *dst,const env_t src);
102    
103  /**  /**
104   * Creates a list of the var=value pairs from src which have varname in list.   * Creates a list of the var=value pairs from src which have varname in list.
# Line 98  char **safe_copy_env(char **dst,const ch Line 106  char **safe_copy_env(char **dst,const ch
106   * using dst==NULL, but this is more efficiently coded. All new entries are   * using dst==NULL, but this is more efficiently coded. All new entries are
107   * strdup-ed from those in src.   * strdup-ed from those in src.
108   */   */
109  char **copy_src_list(const char **src,const char **list);  env_t copy_src_list(const env_t src,const char **list);
110    
111  /**  /**
112   * Adds to dst the var=value pairs from src which have varname in list.   * Adds to dst the var=value pairs from src which have varname in list.
113   * All entries will be strdup-ed from those in src.   * All entries will be strdup-ed from those in src.
114   * If dst is NULL, it will create a new one. dst will be realloc-ed. If it fails   * If *dst is NULL, it will be malloc-ed, otherwise it will be realloc-ed.
115   * NULL is returned, when failure occurs later on, dst will be returned, being   * Upon success returns 0. On error -1 is returned, and dst stays unchanged.
  * equal to the original src but at a different memory location.  
116   * See also copy_src_list() which is more efficient when dst is NULL !   * See also copy_src_list() which is more efficient when dst is NULL !
117   */   */
118  char **add_src_list(char **dst,const char **src,const char **list);  int add_src_list(env_t *dst,const env_t src,const char **list);
119    
120  /**  /**
121   * adds var=value pair to dst. If the variable already exists, it's entry is   * adds var=value pair to dst. If the variable already exists, it's entry is
122   * replaced. Otherwise dst is realloc-ed and a new entry is added, the resulting   * replaced. Otherwise *dst is realloc-ed and a new entry is added, the
123   * array is returned. In case of error NULL is returned and dst is unchanged.   * resulting array is returned.
124   * namevalue is strdup-ed into dst and hence can be freed by the caller (unlike   * Upon success returns 0. In case of error -1 is returned and dst remains
125   * putenv(3p) )   * unchanged. namevalue is strdup-ed into dst and hence can be freed by the
126     * caller (unlike putenv(3p) )
127   */   */
128  char **add_namevalue(char **dst,const char *namevalue);  int add_namevalue(env_t *dst,const char *namevalue);
129    
130  /**  /**
131   * adds name=value pair to dst, as in setenv() with a 'external environment' .   * adds name=value pair to dst, as in setenv() with a 'external environment' .
132   * If the variable already exists, it's entry is replaced. Otherwise dst is   * If the variable already exists, it's entry is replaced. Otherwise *dst is
133   * realloc-ed and a new entry is added, the resulting array is returned. In case   * realloc-ed and a new entry is added.
134   * of error NULL is returned and dst is unchanged. name and value can be freed   * Upon success returns 0. In case of error -1 is returned and dst remains
135   * by the caller (unlike putenv(3p) )   * unchanged. name and value can be freed by the caller (unlike putenv(3p) )
136   */   */
137  char **setenv_dst(char **dst,const char *name, const char *value);  int setenv_dst(env_t *dst,const char *name, const char *value);
138    
139  /**  /**
140   * 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
# Line 134  char **setenv_dst(char **dst,const char Line 142  char **setenv_dst(char **dst,const char
142   * NOTE: putenv doesn't reserve new memory so src should NOT be   * NOTE: putenv doesn't reserve new memory so src should NOT be
143   * free()d.   * free()d.
144   */   */
145  int putenv_src_list(char **src,const char **list);  int putenv_src_list(env_t src,const char **list);
146    
147  /**  /**
148   * Adds to the current environment the var=value pairs from src which start with   * Adds to the current environment the var=value pairs from src which start with
# Line 142  int putenv_src_list(char **src,const cha Line 150  int putenv_src_list(char **src,const cha
150   * NOTE: putenv doesn't reserve new memory so src should NOT be   * NOTE: putenv doesn't reserve new memory so src should NOT be
151   * free()d.   * free()d.
152   */   */
153  int putenv_src_pattern(char **src,const char *pattern);  int putenv_src_pattern(env_t src,const char *pattern);
154    
155    #endif

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

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