William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 1 | // Copyright 2018 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 | // +build aix |
| 6 | // +build ppc64 |
| 7 | |
| 8 | package unix |
| 9 | |
| 10 | //sysnb Getrlimit(resource int, rlim *Rlimit) (err error) |
| 11 | //sysnb Setrlimit(resource int, rlim *Rlimit) (err error) |
| 12 | //sys Seek(fd int, offset int64, whence int) (off int64, err error) = lseek |
| 13 | |
| 14 | //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) = mmap64 |
| 15 | |
| 16 | func setTimespec(sec, nsec int64) Timespec { |
| 17 | return Timespec{Sec: sec, Nsec: nsec} |
| 18 | } |
| 19 | |
| 20 | func setTimeval(sec, usec int64) Timeval { |
| 21 | return Timeval{Sec: int64(sec), Usec: int32(usec)} |
| 22 | } |
| 23 | |
| 24 | func (iov *Iovec) SetLen(length int) { |
| 25 | iov.Len = uint64(length) |
| 26 | } |
| 27 | |
| 28 | func (msghdr *Msghdr) SetControllen(length int) { |
| 29 | msghdr.Controllen = uint32(length) |
| 30 | } |
| 31 | |
David Bainbridge | 788e520 | 2019-10-21 18:49:40 +0000 | [diff] [blame] | 32 | func (msghdr *Msghdr) SetIovlen(length int) { |
| 33 | msghdr.Iovlen = int32(length) |
| 34 | } |
| 35 | |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 36 | func (cmsg *Cmsghdr) SetLen(length int) { |
| 37 | cmsg.Len = uint32(length) |
| 38 | } |
Abhilash S.L | 3b49463 | 2019-07-16 15:51:09 +0530 | [diff] [blame] | 39 | |
| 40 | // In order to only have Timespec structure, type of Stat_t's fields |
| 41 | // Atim, Mtim and Ctim is changed from StTimespec to Timespec during |
| 42 | // ztypes generation. |
| 43 | // On ppc64, Timespec.Nsec is an int64 while StTimespec.Nsec is an |
| 44 | // int32, so the fields' value must be modified. |
| 45 | func fixStatTimFields(stat *Stat_t) { |
| 46 | stat.Atim.Nsec >>= 32 |
| 47 | stat.Mtim.Nsec >>= 32 |
| 48 | stat.Ctim.Nsec >>= 32 |
| 49 | } |
| 50 | |
| 51 | func Fstat(fd int, stat *Stat_t) error { |
| 52 | err := fstat(fd, stat) |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | fixStatTimFields(stat) |
| 57 | return nil |
| 58 | } |
| 59 | |
| 60 | func Fstatat(dirfd int, path string, stat *Stat_t, flags int) error { |
| 61 | err := fstatat(dirfd, path, stat, flags) |
| 62 | if err != nil { |
| 63 | return err |
| 64 | } |
| 65 | fixStatTimFields(stat) |
| 66 | return nil |
| 67 | } |
| 68 | |
| 69 | func Lstat(path string, stat *Stat_t) error { |
| 70 | err := lstat(path, stat) |
| 71 | if err != nil { |
| 72 | return err |
| 73 | } |
| 74 | fixStatTimFields(stat) |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | func Stat(path string, statptr *Stat_t) error { |
| 79 | err := stat(path, statptr) |
| 80 | if err != nil { |
| 81 | return err |
| 82 | } |
| 83 | fixStatTimFields(statptr) |
| 84 | return nil |
| 85 | } |