开发者

Current user path in Linux?

How can I get the current user开发者_高级运维 path in Linux? It can be either with the GTK+ framework APIs, or plain C++.


Assuming you mean the current directory of the process:

  • The plain POSIX C function is getcwd().
  • In glib, there's also g_get_current_dir().


If you want to get home directory use getenv("HOME")


g_get_home_dir() from Glib is more cross-platform than getenv("HOME"). It also prefers /etc/passwd entries over the HOME variable for various reasons discussed at the aforementioned link.


Not sure whether you're wanting the contents of $PATH or the user's current working directory. However to cover both options...

PATH is an environment variable, so you can access this with getenv(), in this instance getenv("PATH"), and is defined in <stdlib.h>.

The current working directory can be obtained with getcwd(), and is defined in <unistd.h>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜