homedir.go 571 B

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