I have researched a lot on this topic but could not get anything substantial. By normalize/canonicalize I mean to remove all the "..", ".", multiple slashes etc from a file path and get a simple absolute path. e.g.
"/rootdir/dir1/dir2/dir3/../././././dir4//////////" to "/rootdir/dir1/dir2/dir4"
On windows I have GetFullPathName() and I can get the canonical filepath name, but for Linux I cannot find any such API which can do the same work for me, realpath() is there, but even realpath() needs the filepath to be present on the file system to be able to output normalized path, e.g. if the path /rootdir/dir1/dir2/dir4 is not on file system - realpath() will throw error on the above specified complex filepath input. Is there any way by which one could get the normalized file path even if it is not existing on the file system?