How can I convert a relative path to an absolute path in C on Unix? Is there a convenient system function for this?
On Windows there is a GetFullPathName
There is also a small path library cwalk which works cross-platform. It has cwk_path_get_absolute to do that:
#include
#include
#include
#include
int main(int argc, char *argv[])
{
char buffer[FILENAME_MAX];
cwk_path_get_absolute("/hello/there", "./world", buffer, sizeof(buffer));
printf("The absolute path is: %s", buffer);
return EXIT_SUCCESS;
}
Outputs:
The absolute path is: /hello/there/world