about summary refs log tree commit diff
path: root/tools/numap/internal/sysfs/parse.go
blob: d518653341078a17c172c9ab2deaecd8da224f86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package sysfs

import (
	"io/ioutil"
	"strconv"
	"strings"
)

// ContentUint64 parses the content of a file in sysfs, and convert
// from hex to uint64.
func ContentUint64(path string) (uint64, error) {
	content, err := ioutil.ReadFile(path)
	if err != nil {
		return 0, err
	}
	result, err := strconv.ParseUint(strings.TrimSpace(string(content)), 0, 64)
	if err != nil {
		return 0, err
	}
	return result, nil
}