-
Notifications
You must be signed in to change notification settings - Fork 658
/
os_posix.go
48 lines (41 loc) · 863 Bytes
/
os_posix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// +build !windows
package main
import (
"flag"
"os"
"os/exec"
"path/filepath"
)
func create_sock_flag(name, desc string) *string {
return flag.String(name, "unix", desc)
}
// Full path of the current executable
func get_executable_filename() string {
// try readlink first
path, err := os.Readlink("/proc/self/exe")
if err == nil {
return path
}
// use argv[0]
path = os.Args[0]
if !filepath.IsAbs(path) {
cwd, _ := os.Getwd()
path = filepath.Join(cwd, path)
}
if file_exists(path) {
return path
}
// Fallback : use "gocode" and assume we are in the PATH...
path, err = exec.LookPath("gocode")
if err == nil {
return path
}
return ""
}
// config location
func config_dir() string {
return filepath.Join(xdg_home_dir(), "gocode")
}
func config_file() string {
return filepath.Join(xdg_home_dir(), "gocode", "config.json")
}