Current user path on Linux?

How can I get the current user path in Linux? It can be either with the GTK + framework API or with simple C ++.

+3
source share
4 answers

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

+1
source

Assuming you mean the current process directory:

+4
source

g_get_home_dir() Glib -, getenv("HOME"). /etc/passwd HOME , .

+2

Not sure if you want the contents of the contents of PATH or the current working directory of the user. However, to cover both options ...

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

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

+1
source

Source: https://habr.com/ru/post/1780403/


All Articles