Source file src/time/sys_windows.go

     1  // Copyright 2011 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  package time
     6  
     7  import (
     8  	"errors"
     9  	"syscall"
    10  )
    11  
    12  // for testing: whatever interrupts a sleep
    13  func interrupt() {
    14  }
    15  
    16  func open(name string) (uintptr, error) {
    17  	fd, err := syscall.Open(name, syscall.O_RDONLY, 0)
    18  	if err != nil {
    19  		// This condition solves issue https://go.dev/issue/50248
    20  		if err == syscall.ERROR_PATH_NOT_FOUND {
    21  			err = syscall.ENOENT
    22  		}
    23  		return 0, err
    24  	}
    25  	return uintptr(fd), nil
    26  }
    27  
    28  func read(fd uintptr, buf []byte) (int, error) {
    29  	return syscall.Read(syscall.Handle(fd), buf)
    30  }
    31  
    32  func closefd(fd uintptr) {
    33  	syscall.Close(syscall.Handle(fd))
    34  }
    35  
    36  func preadn(fd uintptr, buf []byte, off int) error {
    37  	whence := seekStart
    38  	if off < 0 {
    39  		whence = seekEnd
    40  	}
    41  	if _, err := syscall.Seek(syscall.Handle(fd), int64(off), whence); err != nil {
    42  		return err
    43  	}
    44  	for len(buf) > 0 {
    45  		m, err := syscall.Read(syscall.Handle(fd), buf)
    46  		if m <= 0 {
    47  			if err == nil {
    48  				return errors.New("short read")
    49  			}
    50  			return err
    51  		}
    52  		buf = buf[m:]
    53  	}
    54  	return nil
    55  }
    56  

View as plain text