~ubuntu-core-dev/ubuntu/raring/upstart/raring

« back to all changes in this revision

Viewing changes to init/environ.c

  • Committer: Stéphane Graber
  • Date: 2013-03-07 18:43:01 UTC
  • mfrom: (1182.56.54 upstart)
  • Revision ID: stgraber@ubuntu.com-20130307184301-dlmb1c5bwonqagkw
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
155
155
}
156
156
 
157
157
/**
 
158
 * environ_remove:
 
159
 * @env: pointer to environment table,
 
160
 * @parent: parent object for new array,
 
161
 * @len: length of @env,
 
162
 * @str: string to remove.
 
163
 *
 
164
 * Remove @str from environment table @env. If @str does not exist in
 
165
 * @env, the returned array will have the same contents as the original
 
166
 * @env.
 
167
 *
 
168
 * Returns: new array pointer or NULL if insufficient memory (or @env is
 
169
 * too small to reduce).
 
170
 **/
 
171
char **
 
172
environ_remove (char        ***env,
 
173
                const void    *parent,
 
174
                size_t        *len,
 
175
                const char    *str)
 
176
{
 
177
        size_t    _len;
 
178
        size_t    keylen;
 
179
        size_t    new_len = 0;
 
180
        char    **e;
 
181
        char    **new_env;
 
182
 
 
183
        nih_assert (env);
 
184
        nih_assert (str);
 
185
 
 
186
        if (! len) {
 
187
                len = &_len;
 
188
 
 
189
                _len = 0;
 
190
                for (e = *env; e && *e; e++)
 
191
                        _len++;
 
192
        }
 
193
 
 
194
        /* Can't manipulate an empty array */
 
195
        if (*len < 1)
 
196
                return NULL;
 
197
 
 
198
        new_env = nih_str_array_new (NULL);
 
199
        if (! new_env)
 
200
                return NULL;
 
201
 
 
202
        for (e = *env; e && *e; e++) {
 
203
                keylen = strcspn (*e, "=");
 
204
 
 
205
                if (! strncmp (str, *e, keylen))
 
206
                        continue;
 
207
 
 
208
                if (! environ_add (&new_env, parent, &new_len, TRUE, *e))
 
209
                        return NULL;
 
210
        }
 
211
 
 
212
        *env = new_env;
 
213
        *len = new_len;
 
214
 
 
215
        return new_env;
 
216
}
 
217
 
 
218
/**
158
219
 * environ_append:
159
220
 * @env: pointer to environment table,
160
221
 * @parent: parent object for new array,