File: env_from_array.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,500 kB
  • sloc: ansic: 15,824; perl: 674; sh: 63; makefile: 29
file content (29 lines) | stat: -rw-r--r-- 639 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <string.h>
#include "str.h"
#include "envstr.h"

/** Adds the assignments from the array of pointers to the environment
 * string.
 * The array must be terminated by a \c NULL pointer, just the same as
 * the standard \c environ array. */
int envstr_from_array(struct str* env, char** array, int overwrite)
{
  while (*array) {
    if (!envstr_put(env, *array, overwrite))
      return 0;
    ++array;
  }
  return 1;
}

#ifdef SELFTEST_MAIN
MAIN
{
  static str env;
  char* array[3] = {"A=1","B=2",0};
  debugstrfn(envstr_from_array(&env, array, 1), &env);
}
#endif
#ifdef SELFTEST_EXP
result=1 len=8 size=16 s=A=1^@B=2^@
#endif