~xnox/ubuntu/vivid/upstart/fix-rotate-logs

« back to all changes in this revision

Viewing changes to init/environ.c

  • Committer: James Hunt
  • Date: 2014-07-17 13:14:00 UTC
  • mfrom: (1436.2.7)
  • Revision ID: james.hunt@ubuntu.com-20140717131400-airqibye4266cazq
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
176
176
{
177
177
        size_t    _len;
178
178
        size_t    keylen;
179
 
        size_t    new_len = 0;
180
179
        char    **e;
181
 
        char    **new_env;
182
180
 
183
181
        nih_assert (env);
184
182
        nih_assert (str);
195
193
        if (*len < 1)
196
194
                return NULL;
197
195
 
198
 
        new_env = nih_str_array_new (NULL);
199
 
        if (! new_env)
200
 
                return NULL;
201
 
 
202
196
        for (e = *env; e && *e; e++) {
203
197
                keylen = strcspn (*e, "=");
204
198
 
206
200
                 * name=value pair, or a bare name), so don't copy it to
207
201
                 * the new environment.
208
202
                 */
209
 
                if (! strncmp (str, *e, keylen))
210
 
                        continue;
211
 
 
212
 
                if (! environ_add (&new_env, parent, &new_len, TRUE, *e))
213
 
                        return NULL;
 
203
                if (! strncmp (str, *e, keylen)) {
 
204
                        nih_unref (*e, *env);
 
205
 
 
206
                        /* shuffle up the remaining entries */
 
207
                        memmove (e, e + 1, (char *)(*env + *len) - (char *)e);
 
208
 
 
209
                        (*len)--;
 
210
                }
214
211
        }
215
212
 
216
 
        *env = new_env;
217
 
        *len = new_len;
 
213
        /* shrink amount of memory used */
 
214
        if (! nih_realloc (*env, parent, sizeof (**env) * (*len + 1)))
 
215
                return NULL;
218
216
 
219
 
        return new_env;
 
217
        return *env;
220
218
}
221
219
 
222
220
/**