You need to resolve the path of a file provided by a user to determine the actual file that it refers to on the filesystem.
systems, use the function
resolve the canonical name of a file or path. On
Windows, use the function
GetFullPathName( ) to resolve the canonical name
of a file or path.
You must be careful when making access decisions for a file. Taking relative pathnames and links into account, it is possible for multiple filenames to refer to the same file. Failure to take this into account when attempting to perform access checks based on filename can have severe consequences.
On the surface, resolving the canonical name of a file or path may appear to be a reasonably simple task to undertake. However, many programmers fail to consider symbolic and hard links. On Windows, links are possible, but they are not as serious an issue as they are on Unix because they are much less frequently used.
Fortunately, most modern Unix systems provide, as part of the
standard C runtime, a function called
that will properly resolve the canonical name of a file or path,
taking relative paths and links into account. Be careful when using
realpath( ) because the function is not
thread-safe, and the resolved path is stored in a fixed-size buffer
that must be at least
MAXPATHLEN bytes in size.
realpath( ) is not thread-safe because it changes the current directory as it resolves ...