OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [argz/] [envz_add.c] - Blame information for rev 297

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* Copyright (C) 2002 by  Red Hat, Incorporated. All rights reserved.
2
 *
3
 * Permission to use, copy, modify, and distribute this software
4
 * is freely granted, provided that this notice is preserved.
5
 */
6
 
7
#include <errno.h>
8
#include <sys/types.h>
9
#include <string.h>
10
#include <stdlib.h>
11
#include <argz.h>
12
#include <envz.h>
13
 
14
error_t
15
_DEFUN (envz_add, (envz, envz_len, name, value),
16
       char **envz _AND
17
       size_t *envz_len _AND
18
       const char *name _AND
19
       const char *value)
20
{
21
  char *concat = NULL;
22
  int name_len = 0;
23
  int val_len = 0;
24
  int retval = 0;
25
 
26
  envz_remove(envz, envz_len, name);
27
 
28
  if (value)
29
    {
30
      name_len = strlen(name);
31
      val_len = strlen(value);
32
      if(!(concat = (char *) malloc(name_len + val_len + 2)))
33
        return ENOMEM;
34
 
35
      memcpy(concat, name, name_len);
36
      concat[name_len] = '=';
37
      memcpy(concat + name_len + 1, value, val_len + 1);
38
 
39
      retval = argz_add(envz, envz_len, concat);
40
      free(concat);
41
    }
42
  else
43
    {
44
      retval = argz_add(envz, envz_len, name);
45
    }
46
  return retval;
47
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.