You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gopsutil/common.go

50 lines
797 B
Go

//
// gopsutil is a port of psutil(http://pythonhosted.org/psutil/).
// This covers these architectures.
// - linux
// - freebsd
// - window
package gopsutil
11 years ago
import (
"bufio"
"os"
"strings"
)
// Read contents from file and split by new line.
func ReadLines(filename string) ([]string, error) {
f, err := os.Open(filename)
if err != nil {
return []string{""}, err
}
defer f.Close()
ret := make([]string, 0)
r := bufio.NewReader(f)
line, err := r.ReadString('\n')
for err == nil {
ret = append(ret, strings.Trim(line, "\n"))
line, err = r.ReadString('\n')
}
return ret, err
}
11 years ago
func byteToString(orig []byte) string {
n := -1
for i, b := range orig {
if b == 0 {
break
}
n = i + 1
}
11 years ago
if n == -1 {
return string(orig)
11 years ago
} else {
return string(orig[:n])
}
}