time_fake.go 677 B

1234567891011121314151617181920212223242526
  1. // Copyright 2019 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. //go:build faketime
  5. package syscall
  6. import "unsafe"
  7. const faketime = true
  8. // When faketime is enabled, we redirect writes to FDs 1 and 2 through
  9. // the runtime's write function, since that adds the framing that
  10. // reports the emulated time.
  11. //go:linkname runtimeWrite runtime.write
  12. func runtimeWrite(fd uintptr, p unsafe.Pointer, n int32) int32
  13. func faketimeWrite(fd int, p []byte) int {
  14. var pp *byte
  15. if len(p) > 0 {
  16. pp = &p[0]
  17. }
  18. return int(runtimeWrite(uintptr(fd), unsafe.Pointer(pp), int32(len(p))))
  19. }