...
Code Block | ||
---|---|---|
| ||
void f() { char path[PATH_MAX]; /* assume $PATH must be defined is defined and no longer than PATH_MAX characters */ strcpy(path, getenv("PATH")); /* use path */ } |
...
Code Block | ||
---|---|---|
| ||
void f() { char *copy = NULL; /* avoid assuming $PATH must be defined is defined or has limited length */ const char *temp = getenv("PATH"); if (temp != NULL) { path = (char*) malloc(strlen(temp) + 1); if (copy == NULL) { /* Handle error condition */ } else { strcpy(path, temp); } /* use path */ } } |
...