I would like check if a path is a subpath of another path, so I call realpath(file_path, NULL) and compare the result with strncmp.
The reason I wrote this topic is: realpath sets errno to access denied. I would like to create a file if part of this path is a subpath of some directory, so the file can't exist before calling realpath.
Is there a realpath equivalent in Linux/Unix/C, which doesn't check that the file exists? It can also don't follow by symbolic links.
Imagine I have directory "/tmp/tao-client-aaaaaa/classes/" and I just want to create (a file) "/tmp/tao-client-aaaaaa/classes/parent/parent generating test", because of application(server) asks to create "/parent/parent generating test". And the problem was I cannot create the directory named "parent", because it could be ".." and realpath will returns error, while I test file, which will be created in non-existent directory.
I think, that I could implement realpath by myself, but I hear that Unicode have many characters or character connection meaning parent directory.
I have idea. I can create function which adds to path next directory, uses realpath and test result of realpath is child directory of argument (called path). Next it returns null if condition don't pass or realpath result if condition passes. Wrapper will create that directory and get next directory from path to save file and pass it to this function in this way result_path = test_real_path(result_path, next_directory).
But it's not very good solution, because I create directories and I don't know what do if result will not be child of path. Just remove all created directories?