boom
boom

Reputation: 6166

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++.

Upvotes: 4

Views: 2031

Answers (4)

ptomato
ptomato

Reputation: 57880

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.

Upvotes: 3

DReJ
DReJ

Reputation: 1974

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

Upvotes: 2

Callie J
Callie J

Reputation: 31306

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>.

Upvotes: 1

unwind
unwind

Reputation: 399871

Assuming you mean the current directory of the process:

Upvotes: 6

Related Questions