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
|
package main
import (
"os"
"strconv"
)
// updateHsu replaces the hsurc file.
func updateHsu(pairs [][2]uint32) error {
w, err := os.OpenFile(
"/misc/hsurc",
os.O_CREATE|os.O_TRUNC|os.O_WRONLY,
0400,
)
if err != nil {
return err
}
buf := make([]byte, 0, os.Getpagesize())
for _, pair := range pairs {
buf = buf[:0]
buf = strconv.AppendUint(buf, uint64(pair[0]), 10)
buf = append(buf, ' ')
buf = strconv.AppendUint(buf, uint64(pair[1]), 10)
buf = append(buf, '\n')
if _, err = w.Write(buf); err != nil {
_ = w.Close()
return err
}
}
return w.Close()
}
|