...
Code Block | ||
---|---|---|
| ||
char *tmpvar; char *tempvar; size_t len; errno_t err = _dupenv_s(&tmpvar, &len, "TMP"); if (err) return -1; errno_t err = _dupenv_s(&tempvar, &len, "TEMP"); if (err) { free(tmpvar); return -1; } free(pValue); err = _dupenv_s(&pValue, &len, "nonexistentvariable"); if (err) return -1; printf("nonexistentvariable = %s\n", pValueif (strcmp(tmpvar, tempvar) == 0) { puts("TMP and TEMP are the same.\n"); } else { puts("TMP and TEMP are NOT the same.\n"); } free(tmpvar); free(pValuetempvar); // It's OK to call free with NULL |
Compliant Solution (POSIX)
...