![]() ![]() If we already know that the given input file exists, then still the given output file may exist or not. And, in that case, realpath() will be able to resolve the absolute (canonical) path of the input file. So, the only relevant case is when the input file does exist. If the given input file does not exist, then we are going to fail anyway, because fopen() is going to fail to open the non-existing input file for reading. If it doesn't, then prepend the current working directory, as returned by getcwd() function)Īfter thinking about this a little more, I believe that I can get along with realpath() □ (The best solution that I have come up with, so far, is to manually test whether the path starts with a slash. Also, I really want to avoid using 3rd-party libraries, otherwise something like cwalk could probably do the job. Please also note that the program is written in "plain" C, so no C++ is available. Note: GetFullPathName() on Windows does not require the file to exist! The output file does not usually exist, though. Is there an equivalent in POSIX API on Linux/Unix? Unfortunately, I can not use realpath(), because it only works with existing files. On Windows, I could use GetFullPathName() for that purpose. So, I want to convert the file names to absolute paths before comparing them. For example, "foo.txt", "./foo.txt" and "/full/path/foo.txt" would still be the same file, even though the strings are obviously different. ![]() However, a simple strcmp() would only catch the most trivial cases. I want to make sure that the user does not specify both as the same file, because this would result is trouble. I have a program that takes an input and output file as arguments.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |