In C on linux, given a file path, I'd like to read the file contents, and also I'd like to know the real path with any symlinks resolved. I can do those things separately (e.g. open()
+ read()
for the former, realpath()
for the latter), but it feels there's some redundant work happening, because doesn't open()
already have to follow all the symlinks internally? Is there a way to somehow access that result and get both the file descriptor and the real path in one operation, instead of having realpath()
do the resolution a second time?
Intuitively it feels like it might be faster to do the realpath()
first and then pass the resolved path to open()
, but I guess open()
will still have to check whether any of the path components are symlinks even though I know they aren't.