File: setenv.c

package info (click to toggle)
cvm 0.11-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 492 kB
  • ctags: 215
  • sloc: ansic: 1,777; makefile: 48; sh: 12
file content (20 lines) | stat: -rw-r--r-- 475 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "setenv.h"
#include <stdlib.h>
#include <string.h>

#ifndef HASSETENV
int setenv(const char* name, const char* value, int overwrite)
{
  char* newenv;
  size_t namelen;
  size_t valuelen;
  if (!overwrite && getenv(name)) return 0;
  namelen = strlen(name);
  valuelen = strlen(value);
  newenv = malloc(namelen+1+valuelen+1);
  memcpy(newenv, name, namelen);
  newenv[namelen] = '=';
  memcpy(newenv+namelen+1, value, valuelen+1);
  return putenv(newenv);
}
#endif