linux C++ 获取文件绝对路径

提供ftp服务时需要获取文件绝对路径,这里记录一下。

 1 #include <stdlib.h>
 2 #include <stdio.h>
 3 #include <limits.h>
 4 
 5 int main(){
 6     const char *file_name = "filename";
 7     char abs_path_buff[PATH_MAX];
 8 
 9     //获取文件路径, 填充到abs_path_buff
10     //realpath函数返回: null表示获取失败; 否则返回指向abs_path_buff的指针
11     if(realpath(file_name, abs_path_buff)){
12         printf("%s %s
", file_name, abs_path_buff);
13     }
14     else{
15         printf("the file '%s' is not exist
", file_name);    
16     }
17 
18     return 0;
19 }
原文地址:https://www.cnblogs.com/xudong-bupt/p/5467735.html