How to get the absolute path for a given relative path programmatically in Linux?

后端 未结 7 1822
轻奢々
轻奢々 2020-12-05 07:33

How to get the absolute path for a given relative path programmatically in Linux?

Incase of Windows we have the _fullpath() API. In other words, I mean

7条回答
  •  情歌与酒
    2020-12-05 08:18

    Check out the realpath function.

    #include  
    #include  
    #include 
    int main() 
    { 
            char resolved_path[PATH_MAX]; 
            realpath("../../", resolved_path); 
            printf("\n%s\n",resolved_path); 
            return 0; 
    } 
    

提交回复
热议问题