Possible Duplicate:
How to check whether two file names point to the same physical file
How can I know if two hardlinks are connected to one file from C in Linux.
Thanks.
Use the stat() or fstat() function for both paths. If in the returned structures both the st_dev and st_ino fields are identical, then the paths refer to the same filesystem object.
EDIT:
Note that you need to check both st_dev and st_ino. Otherwise you run the risk of matching two files in different filesystems that just happen to have the same inode number. You may be able to see this if you run stat
on two mountpoints:
$ stat / /boot | grep Device
Device: 903h/2307d Inode: 2 Links: 23
Device: 902h/2306d Inode: 2 Links: 3
You can clearly see the identical inode numbers in the output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With