| Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 1 | // Copyright 2019 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 | |
| khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 5 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos |
| Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 6 | |
| 7 | package unix |
| 8 | |
| 9 | // Set adds fd to the set fds. |
| 10 | func (fds *FdSet) Set(fd int) { |
| 11 | fds.Bits[fd/NFDBITS] |= (1 << (uintptr(fd) % NFDBITS)) |
| 12 | } |
| 13 | |
| 14 | // Clear removes fd from the set fds. |
| 15 | func (fds *FdSet) Clear(fd int) { |
| 16 | fds.Bits[fd/NFDBITS] &^= (1 << (uintptr(fd) % NFDBITS)) |
| 17 | } |
| 18 | |
| 19 | // IsSet returns whether fd is in the set fds. |
| 20 | func (fds *FdSet) IsSet(fd int) bool { |
| 21 | return fds.Bits[fd/NFDBITS]&(1<<(uintptr(fd)%NFDBITS)) != 0 |
| 22 | } |
| 23 | |
| 24 | // Zero clears the set fds. |
| 25 | func (fds *FdSet) Zero() { |
| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 26 | clear(fds.Bits[:]) |
| Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 27 | } |