cur_file is an argument from the command line. I've used the absolute path for testing, though it works the same way if I gave it the basename (a) for an argument - the path still resolves to the absolute path and errno is set to 2.
Code:
char real_path[PATH_MAX];
printf ("%d\n", errno);
if (realpath (cur_file, real_path) == NULL)
{
printf ("%d\n", errno);
perror ("realpath");
printf ("%s\n", cur_file);
printf ("%s\n", real_path);
}
Output:
0
2
realpath: No such file or directory
/home/andy/temp/a
/home/andy/temp/a
Can anyone tell me why realpath() is saying there's no such file, even though it can resolve the path successfully?