summaryrefslogtreecommitdiffstats
path: root/src/internal/syscall/unix/user_darwin.go
blob: d05acdaa490514f22b12870f0a24cf18b80e0b50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package unix

import (
	"internal/abi"
	"syscall"
	"unsafe"
)

//go:cgo_import_dynamic libc_getgrouplist getgrouplist "/usr/lib/libSystem.B.dylib"
func libc_getgrouplist_trampoline()

func Getgrouplist(name *byte, gid uint32, gids *uint32, n *int32) error {
	_, _, errno := syscall_syscall6(abi.FuncPCABI0(libc_getgrouplist_trampoline),
		uintptr(unsafe.Pointer(name)), uintptr(gid), uintptr(unsafe.Pointer(gids)),
		uintptr(unsafe.Pointer(n)), 0, 0)
	if errno != 0 {
		return errno
	}
	return nil
}

const (
	SC_GETGR_R_SIZE_MAX = 0x46
	SC_GETPW_R_SIZE_MAX = 0x47
)

type Passwd struct {
	Name   *byte
	Passwd *byte
	Uid    uint32 // uid_t
	Gid    uint32 // gid_t
	Change int64  // time_t
	Class  *byte
	Gecos  *byte
	Dir    *byte
	Shell  *byte
	Expire int64 // time_t
}

type Group struct {
	Name   *byte
	Passwd *byte
	Gid    uint32 // gid_t
	Mem    **byte
}

//go:cgo_import_dynamic libc_getpwnam_r getpwnam_r  "/usr/lib/libSystem.B.dylib"
func libc_getpwnam_r_trampoline()

func Getpwnam(name *byte, pwd *Passwd, buf *byte, size uintptr, result **Passwd) syscall.Errno {
	// Note: Returns an errno as its actual result, not in global errno.
	errno, _, _ := syscall_syscall6(abi.FuncPCABI0(libc_getpwnam_r_trampoline),
		uintptr(unsafe.Pointer(name)),
		uintptr(unsafe.Pointer(pwd)),
		uintptr(unsafe.Pointer(buf)),
		size,
		uintptr(unsafe.Pointer(result)),
		0)
	return syscall.Errno(errno)
}

//go:cgo_import_dynamic libc_getpwuid_r getpwuid_r  "/usr/lib/libSystem.B.dylib"
func libc_getpwuid_r_trampoline()

func Getpwuid(uid uint32, pwd *Passwd, buf *byte, size uintptr, result **Passwd) syscall.Errno {
	// Note: Returns an errno as its actual result, not in global errno.
	errno, _, _ := syscall_syscall6(abi.FuncPCABI0(libc_getpwuid_r_trampoline),
		uintptr(uid),
		uintptr(unsafe.Pointer(pwd)),
		uintptr(unsafe.Pointer(buf)),
		size,
		uintptr(unsafe.Pointer(result)),
		0)
	return syscall.Errno(errno)
}

//go:cgo_import_dynamic libc_getgrnam_r getgrnam_r  "/usr/lib/libSystem.B.dylib"
func libc_getgrnam_r_trampoline()

func Getgrnam(name *byte, grp *Group, buf *byte, size uintptr, result **Group) syscall.Errno {
	// Note: Returns an errno as its actual result, not in global errno.
	errno, _, _ := syscall_syscall6(abi.FuncPCABI0(libc_getgrnam_r_trampoline),
		uintptr(unsafe.Pointer(name)),
		uintptr(unsafe.Pointer(grp)),
		uintptr(unsafe.Pointer(buf)),
		size,
		uintptr(unsafe.Pointer(result)),
		0)
	return syscall.Errno(errno)
}

//go:cgo_import_dynamic libc_getgrgid_r getgrgid_r  "/usr/lib/libSystem.B.dylib"
func libc_getgrgid_r_trampoline()

func Getgrgid(gid uint32, grp *Group, buf *byte, size uintptr, result **Group) syscall.Errno {
	// Note: Returns an errno as its actual result, not in global errno.
	errno, _, _ := syscall_syscall6(abi.FuncPCABI0(libc_getgrgid_r_trampoline),
		uintptr(gid),
		uintptr(unsafe.Pointer(grp)),
		uintptr(unsafe.Pointer(buf)),
		size,
		uintptr(unsafe.Pointer(result)),
		0)
	return syscall.Errno(errno)
}

//go:cgo_import_dynamic libc_sysconf sysconf "/usr/lib/libSystem.B.dylib"
func libc_sysconf_trampoline()

func Sysconf(key int32) int64 {
	val, _, errno := syscall_syscall6X(abi.FuncPCABI0(libc_sysconf_trampoline),
		uintptr(key), 0, 0, 0, 0, 0)
	if errno != 0 {
		return -1
	}
	return int64(val)
}