Is there a way to get the full path of a file in C? I have a method that accepts a file name as an argument and is supposed to read the content of the file. The file name might include "../" so this might lead to accessing files outside of the current directory. I tried to use fstat but I could not figure out how to get the full path.
Code:
void readFile(char *filename) {
FILE *fp;
//char filename[] = "../../debug.log";
fp = fopen(filename, "r");
if (fp == NULL){
printf("Cannot open file[%s]\n", filename);
return;
}
// read the file
fclose(fp);
}
UPDATE: follow-up posted on post
#4