Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
char * libvartmpvar;
char *tempvar;
size_t requiredSize;

getenv_s( &requiredSize, NULL, 0, "LIBTMP");

libvar = malloc(requiredSize * sizeof(char));
if (!libvar) {
   /* handle error condition */
}

// Get the value of the LIB environment variable.getenv_s(&requiredSize, tmpvar, requiredSize, "TMP" );

getenv_s(&requiredSize, NULL, 0, "TEMP");
libvar = malloc(requiredSize * sizeof(char));
if (!libvar) {
   /* handle error condition */
}
getenv_s( &requiredSize, libvartempvar, requiredSize, "LIB" );
"TEMP" );

if (strcmp(tmpvar, tempvar) == 0) {
  puts("TMP and TEMP are the same.\n");
}
else {
  puts("TMP and TEMP are NOT the same.\n");    
}

Compliant Solution (Windows)

...

Code Block
bgColor#ccccff
char *pValuetmpvar;
char *tempvar;
size_t len;

errno_t err = _dupenv_s(&pValuetmpvar, &len, "pathextTMP");
if (err) return -1;
printf("pathext = %s\n", pValue);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", pValue);
free(pValue); // It's OK to call free with NULL

...