syscall_solaris.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2012 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. package syscall
  5. import "unsafe"
  6. func (ts *Timestruc) Unix() (sec int64, nsec int64) {
  7. return int64(ts.Sec), int64(ts.Nsec)
  8. }
  9. func (ts *Timestruc) Nano() int64 {
  10. return int64(ts.Sec)*1e9 + int64(ts.Nsec)
  11. }
  12. func direntIno(buf []byte) (uint64, bool) {
  13. return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
  14. }
  15. func direntReclen(buf []byte) (uint64, bool) {
  16. return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
  17. }
  18. func direntNamlen(buf []byte) (uint64, bool) {
  19. reclen, ok := direntReclen(buf)
  20. if !ok {
  21. return 0, false
  22. }
  23. return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
  24. }
  25. //sysnb getexecname() (execname unsafe.Pointer, err error)
  26. //getexecname() *byte
  27. func Getexecname() (path string, err error) {
  28. ptr, err := getexecname()
  29. if err != nil {
  30. return "", err
  31. }
  32. bytes := (*[1 << 29]byte)(ptr)[:]
  33. for i, b := range bytes {
  34. if b == 0 {
  35. return string(bytes[:i]), nil
  36. }
  37. }
  38. panic("unreachable")
  39. }