github.com/megatontech/mynoteforgo@v0.0.0-20200507084910-5d0c6ea6e890/源码/cmd/compile/internal/gc/mapfile_read.go (about)

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd
     6  
     7  package gc
     8  
     9  import (
    10  	"io"
    11  	"os"
    12  )
    13  
    14  func mapFile(f *os.File, offset, length int64) (string, error) {
    15  	buf := make([]byte, length)
    16  	_, err := io.ReadFull(io.NewSectionReader(f, offset, length), buf)
    17  	if err != nil {
    18  		return "", err
    19  	}
    20  	return string(buf), nil
    21  }