I want to write a unit test that checks that two file paths are equivalent, but I don’t want to assume that the string representation is the same.
For example, on Linux there could be symlinks in the path in one case and not in the other. On Windows, there could be drive notation on one (
X:\foo) and network notation on the other (
//serverX/foo). And most complicated, the file may have been written on Linux on an NFS share (in
/path/to/file syntax) and verified on Windows using DOS syntax (
X: is a NFS mount to
Some ideas (found here on Stack Overflow, but not unified):
- On Linux, compare the inode from
realpath(Is this Platform independent?)
- On Windows, compare strings on
- On Windows, compare serial numbers and file index from
What would be the cross-platform best solution? I’m writing this in C++, but I can drop down to C obviously.