How can I get the current user path in Linux? It can be either with the GTK+ framework APIs, or plain C++.
            Asked
            
        
        
            Active
            
        
            Viewed 1,971 times
        
    4 Answers
6
            
            
        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().
 
    
    
        unwind
        
- 391,730
- 64
- 469
- 606
2
            
            
        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.
 
    
    
        ptomato
        
- 56,175
- 13
- 112
- 165
1
            
            
        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>.
 
    
    
        Chris J
        
- 30,688
- 6
- 69
- 111
 
    