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() }