 
                            ...
After a call to setenv(), environment pointers to the old value and copies of the old value will be incorrect.
| Code Block | ||
|---|---|---|
| 
 | ||
| 
char *temp;
char *copy;
if ((temp = getenv("TEST_ENV")) != NULL) {
  copy = malloc(strlen(temp) + 1);
  if (copy != NULL) {
    strcpy(copy, temp);
  }
  else {
    /* handle error condition */
  }
}
/* ...program code... */
setenv("TEST_ENV", var, 1);
/* ...program code... */
printf("TEST_ENV: %s\n", temp);
printf("TEST_ENV: %s\n", copy);
 | 
...
| Code Block | ||
|---|---|---|
| 
 | ||
| char \*temp; char \*copy; if ((temp = getenv("TEST_ENV")) \!= NULL) { copy = malloc(strlen(temp) + 1); if (copy \!= NULL) { { strcpy(copy, temp); } else { /* handle error condition */ } } /* ...program code... */ setenv("TEST_ENV", var, 1); /* ...program code... */ if ((temp = getenv("TEST_ENV")) != NULL) { copy = malloc(strlen(temp) + 1); if (copy != NULL) { strcpy(copy, temp); } } else { /* handle error condition */ } } printf("TEST_ENV: %s\n", temp); printf("TEST_ENV: %s\n", copy); | 
...