vendor/github.com/godbus/dbus/v5/homedir.go
25 lines · 571 bytes
1package dbus
2
3import (
4 "os"
5 "os/user"
6)
7
8// Get returns the home directory of the current user, which is usually the
9// value of HOME environment variable. In case it is not set or empty, os/user
10// package is used.
11//
12// If linking statically with cgo enabled against glibc, make sure the
13// osusergo build tag is used.
14//
15// If needing to do nss lookups, do not disable cgo or set osusergo.
16func getHomeDir() string {
17 homeDir := os.Getenv("HOME")
18 if homeDir != "" {
19 return homeDir
20 }
21 if u, err := user.Current(); err == nil {
22 return u.HomeDir
23 }
24 return "/"
25}