gcc如何得到执行程序的名字和路径

ckc 2002-09-26 10:33:09
以前在dos下是用argv[0]得到执行程序和路径
现在在linux下用gcc好象只能得到执行程序名,
得不到执行程序所在路径,怎么办?
...全文
97 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
spark_li 2002-10-02
  • 打赏
  • 举报
回复
getcwf
ckc 2002-09-27
  • 打赏
  • 举报
回复
getcwd是得到当前目录
比如我在/home/abc目录下执行/usr/bin/def这个程序
getcwd得到的是/home/abc吧
我需要得到的是/usr/bin/def
有什么好办法
linuxnewer 2002-09-27
  • 打赏
  • 举报
回复
see
blh 2002-09-26
  • 打赏
  • 举报
回复
#include <unistd.h>

char *getcwd(char *buf, size_t size);
char *get_current_dir_name(void);
char *getwd(char *buf);

DESCRIPTION
The getcwd() function copies an absolute pathname of the current working directory
to the array pointed to by buf, which is of length size.

If the current absolute path name would require a buffer longer than size elements,
NULL is returned, and errno is set to ERANGE; an application should check for this
error, and allocate a larger buffer if necessary.

If buf is NULL, the behaviour of getcwd() is undefined.
blh 2002-09-26
  • 打赏
  • 举报
回复
getcwd()
胖和尚minifat 2002-09-26
  • 打赏
  • 举报
回复
getcwd

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧