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