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