I’ve received some curious results while using opendir():
int dtw(char *path) {
struct stat statbuf;
...
else if (S_ISDIR(statbuf.st_mode)) {
printf("Path is: %s\n", path);
struct dirent *dirent;
DIR *dirp;
if ((dirp = opendir(path)) == NULL) {
puts("Can't open directory.");
return -1;
}
printf("Path is: %s\n", path);
}
...
}
Results in:
Path is: /home/.../etc
Path is:
The only thing that would affect path is opendir() here. Does it have side effects that I’m not seeing? Or is there something else at work?
No changes are allowed; the definition of
opendir()is:And the
constsaysopendir()did not change it.I wonder if your
pathis a pointer to freed memory? In that case, the memory may have been allocated toopendir()and you are seeing the change because you’re using a dangling pointer to memory that you should not be looking at?