This code casues my program to crash in C. Its compiles without any errors or warnings. Does anyone know why, or how I can fix this? The two lines of code will both cause program to hang/crash.
pathname = getenv("HTTPPATH");
strcpy(pathname, getenv("HTTPPATH"));
Code:
char pathname[1024];
.
.
.
if (!strcmp(httpGET_PATH, "")) {
chdir(pathname);
count = scandir(pathname, &files, 0, alphasort);
setenv("HTTPPATH", pathname, 0);
}
else {
pathname = getenv("HTTPPATH"); //CAUSES progrma to CRASH.
//strcpy(pathname, getenv("HTTPPATH")); //Also causes to CRASH
strcat(pathname, "/");
strcat(pathname, httpGET_PATH);
count = scandir(pathname, &files, 0, alphasort);
chdir(pathname);
setenv("HTTPPATH", pathname, 0);
}
THANKS