...

Source file src/pkg/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			return 0, err
    20		}
    21		return uintptr(fd), nil
    22	}
    23	
    24	func read(fd uintptr, buf []byte) (int, error) {
    25		return syscall.Read(syscall.Handle(fd), buf)
    26	}
    27	
    28	func closefd(fd uintptr) {
    29		syscall.Close(syscall.Handle(fd))
    30	}
    31	
    32	func preadn(fd uintptr, buf []byte, off int) error {
    33		whence := seekStart
    34		if off < 0 {
    35			whence = seekEnd
    36		}
    37		if _, err := syscall.Seek(syscall.Handle(fd), int64(off), whence); err != nil {
    38			return err
    39		}
    40		for len(buf) > 0 {
    41			m, err := syscall.Read(syscall.Handle(fd), buf)
    42			if m <= 0 {
    43				if err == nil {
    44					return errors.New("short read")
    45				}
    46				return err
    47			}
    48			buf = buf[m:]
    49		}
    50		return nil
    51	}
    52	

View as plain text