In unistd.h
, I have the C function readlink
, which follows a link down one target. The coreutil readlink
has the great -f
option to follow every sym link recursively. How can I get this behavior in C++? A boost library, a posix function I don't know about, etc?
** Edit ** was just looking at the man page for realpath
. Is this giving the same 'canonical' expansion of readlink -f
?
I needed to do exactly this today and the suggestion to use realpath() failed because the symlink was relative! If you are using glibc, consider canonicalize_file_name (https://man7.org/linux/man-pages/man3/canonicalize_file_name.3.html).
Of course, I found that after I wrote this code. I don't know how cross-platform this is. I wouldn't recommend it if canonicalize_file_name is available for you, but it might be a good starting point :)