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.
12 "golang.org/x/sys/unix"
15 // stringsFromByteSlice converts a sequence of attributes to a []string.
16 // On NetBSD, each entry consists of a single byte containing the length
17 // of the attribute name, followed by the attribute name.
18 // The name is _not_ NULL-terminated.
19 func stringsFromByteSlice(buf []byte) []string {
23 next := i + 1 + int(buf[i])
24 result = append(result, string(buf[i+1:next]))
30 func TestIoctlPtmget(t *testing.T) {
31 fd, err := unix.Open("/dev/ptmx", unix.O_NOCTTY|unix.O_RDWR, 0666)
33 t.Skip("failed to open /dev/ptmx, skipping test")
37 ptm, err := unix.IoctlGetPtmget(fd, unix.TIOCPTSNAME)
39 t.Fatalf("IoctlGetPtmget: %v\n", err)
42 t.Logf("sfd = %v, ptsname = %v", ptm.Sfd, string(ptm.Sn[:bytes.IndexByte(ptm.Sn[:], 0)]))
45 func TestStatvfs(t *testing.T) {
49 var statvfs1, statvfs2 unix.Statvfs_t
50 err := unix.Statvfs("file1", &statvfs1)
52 t.Fatalf("Statvfs: %v", err)
55 f, err := os.Open("file1")
61 err = unix.Fstatvfs(int(f.Fd()), &statvfs2)
63 t.Fatalf("Fstatvfs: %v", err)
66 if statvfs2.Fsid != statvfs1.Fsid {
67 t.Errorf("Fstatvfs: got fsid %v, expected %v", statvfs2.Fsid, statvfs1.Fsid)
69 if statvfs2.Owner != statvfs1.Owner {
70 t.Errorf("Fstatvfs: got owner %v, expected %v", statvfs2.Owner, statvfs1.Owner)
72 if statvfs2.Fstypename != statvfs1.Fstypename {
73 t.Errorf("Fstatvfs: got fstypename %s, expected %s", statvfs2.Fstypename, statvfs1.Fstypename)