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