开发者

Current user path in Linux?

开发者 https://www.devze.com 2023-01-30 22:13 出处:网络
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:

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

精彩评论

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

关注公众号