您的位置:首页 > 运维架构 > Linux

Linux中获取当前程序的绝对路径

2016-01-06 13:31 603 查看
代码如下:

char current_absolut_path[MAX_SIZE] = "";
memset(current_absolut_path,0,MAX_SIZE);
//获取当前程序绝对路径
int cnt = readlink("/proc/self/exe", current_absolut_path, MAX_SIZE);
if (cnt < 0 || cnt >= MAX_SIZE)
{

}
else
{
//获取当前目录绝对路径,及去掉程序名
int i;
for (i = cnt; i >= 0; --i)
{
if (current_absolut_path[i] == '/')
{
current_absolut_path[i+1] = '\0';
break;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: