本文整理汇总了Golang中syscall.NsecToTimespec函数的典型用法代码示例。如果您正苦于以下问题:Golang NsecToTimespec函数的具体用法?Golang NsecToTimespec怎么用?Golang NsecToTimespec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NsecToTimespec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestNegativeTime
func TestNegativeTime(t *testing.T) {
ts := NewTestCase(t)
defer ts.Cleanup()
_, err := os.Create(ts.origFile)
if err != nil {
t.Fatalf("Create failed: %v", err)
}
var stat syscall.Stat_t
// set negative nanosecond will occur errors on UtimesNano as invalid argument
ut := time.Date(1960, time.January, 10, 23, 0, 0, 0, time.UTC)
tim := []syscall.Timespec{
syscall.NsecToTimespec(ut.UnixNano()),
syscall.NsecToTimespec(ut.UnixNano()),
}
err = syscall.UtimesNano(ts.mountFile, tim)
if err != nil {
t.Fatalf("UtimesNano failed: %v", err)
}
err = syscall.Lstat(ts.mountFile, &stat)
if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if stat.Atim.Sec >= 0 || stat.Mtim.Sec >= 0 {
t.Errorf("Got wrong timestamps %v", stat)
}
}
示例2: setZeroModTime
func setZeroModTime(filename string) error {
var utimes = []syscall.Timespec{
syscall.NsecToTimespec(0),
syscall.NsecToTimespec(0),
}
return syscall.UtimesNano(filename, utimes)
}
示例3: Chtimes
// Chtimes changes the access and modification times of the named
// file, similar to the Unix utime() or utimes() functions.
//
// The underlying filesystem may truncate or round the values to a
// less precise time unit.
// If there is an error, it will be of type *PathError.
func Chtimes(name string, atime time.Time, mtime time.Time) error {
var utimes [2]syscall.Timespec
utimes[0] = syscall.NsecToTimespec(atime.UnixNano())
utimes[1] = syscall.NsecToTimespec(mtime.UnixNano())
if e := syscall.UtimesNano(name, utimes[0:]); e != nil {
return &PathError{"chtimes", name, e}
}
return nil
}
示例4: UtimesNano
func UtimesNano(path string, atime time.Time, mtime time.Time) error {
var utimes [2]syscall.Timespec
utimes[0] = syscall.NsecToTimespec(atime.UnixNano())
utimes[1] = syscall.NsecToTimespec(mtime.UnixNano())
if err := syscall.UtimesNano(path, utimes[0:]); err != nil {
return &os.PathError{"chtimes", path, err}
}
return nil
}
示例5: WaitFD
func (p *pollster) WaitFD(nsec int64) (fd int, mode int, err os.Error) {
var t *syscall.Timespec
for len(p.events) == 0 {
if nsec > 0 {
if t == nil {
t = new(syscall.Timespec)
}
*t = syscall.NsecToTimespec(nsec)
}
nn, e := syscall.Kevent(p.kq, nil, &p.eventbuf, t)
if e != 0 {
if e == syscall.EINTR {
continue
}
return -1, 0, os.NewSyscallError("kevent", e)
}
if nn == 0 {
return -1, 0, nil
}
p.events = p.eventbuf[0:nn]
}
ev := &p.events[0]
p.events = p.events[1:len(p.events)]
fd = int(ev.Ident)
if ev.Filter == syscall.EVFILT_READ {
mode = 'r'
} else {
mode = 'w'
}
return fd, mode, nil
}
示例6: TimeToTimespec
// TODO(sgotti) use UTIMES_OMIT on linux if Time.IsZero ?
func TimeToTimespec(time time.Time) (ts syscall.Timespec) {
nsec := int64(0)
if !time.IsZero() {
nsec = time.UnixNano()
}
return syscall.NsecToTimespec(nsec)
}
示例7: Kevent
func (p *pollster) Kevent(nsec int64) (result int, events []net_event, err error) {
var t *syscall.Timespec
if nsec > 0 {
if t == nil {
t = new(syscall.Timespec)
}
*t = syscall.NsecToTimespec(nsec)
}
n, err := syscall.Kevent(p.kq, nil, p.eventbuf[:], t)
if err != nil {
if err == syscall.EINTR {
return 0, nil, nil
} else {
return -1, nil, os.NewSyscallError("kevent", err)
}
}
if n == 0 {
return -2, nil, nil
}
events = make([]net_event, n)
for i, ev := range p.eventbuf {
events[i].fd = int(ev.Ident)
events[i].data = int(ev.Data)
if ev.Filter == syscall.EVFILT_READ {
events[i].mode = 'r'
} else {
events[i].mode = 'w'
}
}
return n, events, nil
}
示例8: WaitFD
func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err error) {
var t *syscall.Timespec
for len(p.events) == 0 {
if nsec > 0 {
if t == nil {
t = new(syscall.Timespec)
}
*t = syscall.NsecToTimespec(nsec)
}
s.Unlock()
n, err := syscall.Kevent(p.kq, nil, p.eventbuf[:], t)
s.Lock()
if err != nil {
if err == syscall.EINTR {
continue
}
return -1, 0, os.NewSyscallError("kevent", err)
}
if n == 0 {
return -1, 0, nil
}
p.events = p.eventbuf[:n]
}
ev := &p.events[0]
p.events = p.events[1:]
fd = int(ev.Ident)
if ev.Filter == syscall.EVFILT_READ {
mode = 'r'
} else {
mode = 'w'
}
return fd, mode, nil
}
示例9: RestoreTimestamps
func (node Node) RestoreTimestamps(path string) error {
var utimes = [...]syscall.Timespec{
syscall.NsecToTimespec(node.AccessTime.UnixNano()),
syscall.NsecToTimespec(node.ModTime.UnixNano()),
}
if node.Type == "symlink" {
return node.restoreSymlinkTimestamps(path, utimes)
}
if err := syscall.UtimesNano(path, utimes[:]); err != nil {
return errors.Wrap(err, "UtimesNano")
}
return nil
}
示例10: ClockGettime
func (k *PosixKernel) ClockGettime(_ int, out co.Obuf) uint64 {
ts := syscall.NsecToTimespec(time.Now().UnixNano())
err := out.Pack(&native.Timespec{int64(ts.Sec), int64(ts.Nsec)})
if err != nil {
return UINT64_MAX // FIXME
}
return 0
}
示例11: LUtimesNano
func LUtimesNano(path string, atime time.Time, mtime time.Time) error {
var utimes [2]syscall.Timespec
utimes[0] = syscall.NsecToTimespec(atime.UnixNano())
utimes[1] = syscall.NsecToTimespec(mtime.UnixNano())
var _path *byte
_path, err := syscall.BytePtrFromString(path)
if err != nil {
return err
}
if _, _, err := syscall.Syscall(syscall.SYS_LUTIMES, uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&utimes[0])), 0); err != 0 {
return &os.PathError{"chtimes", path, err}
}
return nil
}
示例12: timeToTimespec
func timeToTimespec(time time.Time) (ts syscall.Timespec) {
if time.IsZero() {
// Return UTIME_OMIT special value
ts.Sec = 0
ts.Nsec = ((1 << 30) - 2)
return
}
return syscall.NsecToTimespec(time.UnixNano())
}
示例13: Utimens
// Utimens - path based version of loopbackFile.Utimens()
func (fs *loopbackFileSystem) Utimens(path string, a *time.Time, m *time.Time, context *fuse.Context) (code fuse.Status) {
var ts [2]syscall.Timespec
if a == nil {
ts[0].Nsec = _UTIME_OMIT
} else {
ts[0] = syscall.NsecToTimespec(a.UnixNano())
ts[0].Nsec = 0
}
if m == nil {
ts[1].Nsec = _UTIME_OMIT
} else {
ts[1] = syscall.NsecToTimespec(m.UnixNano())
ts[1].Nsec = 0
}
err := sysUtimensat(0, fs.GetPath(path), &ts, _AT_SYMLINK_NOFOLLOW)
return fuse.ToStatus(err)
}
示例14: timespec
func (p poller) timespec(d time.Duration) *C.struct_timespec {
if d < 0 {
// a NULL timespec tells kqueue to wait forever
return nil
}
t := syscall.NsecToTimespec(d.Nanoseconds())
// darwin defines tv_sec as __darwin_time_t, so we
// need to to some indirection to let C do the implicit
// type conversion.
ts := C.make_timespec(C.long(t.Sec), C.long(t.Nsec))
return &ts
}
示例15: UtimeToTimespec
// UtimeToTimespec converts a "Time" pointer as passed to Utimens to a
// "Timespec" that can be passed to the utimensat syscall.
// A nil pointer is converted to the special UTIME_OMIT value.
func UtimeToTimespec(t *time.Time) (ts syscall.Timespec) {
if t == nil {
ts.Nsec = _UTIME_OMIT
} else {
ts = syscall.NsecToTimespec(t.UnixNano())
// Go bug https://github.com/golang/go/issues/12777
if ts.Nsec < 0 {
ts.Nsec = 0
}
}
return ts
}