summaryrefslogtreecommitdiff
path: root/vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go')
-rw-r--r--vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go b/vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go
index 1ab875cee..d5404a6d7 100644
--- a/vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go
+++ b/vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go
@@ -20,6 +20,8 @@ package util
import (
"bytes"
"os"
+ "strconv"
+ "strings"
"syscall"
)
@@ -48,3 +50,21 @@ func SysReadFile(file string) (string, error) {
return string(bytes.TrimSpace(b[:n])), nil
}
+
+// SysReadUintFromFile reads a file using SysReadFile and attempts to parse a uint64 from it.
+func SysReadUintFromFile(path string) (uint64, error) {
+ data, err := SysReadFile(path)
+ if err != nil {
+ return 0, err
+ }
+ return strconv.ParseUint(strings.TrimSpace(string(data)), 10, 64)
+}
+
+// SysReadIntFromFile reads a file using SysReadFile and attempts to parse a int64 from it.
+func SysReadIntFromFile(path string) (int64, error) {
+ data, err := SysReadFile(path)
+ if err != nil {
+ return 0, err
+ }
+ return strconv.ParseInt(strings.TrimSpace(string(data)), 10, 64)
+}