gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/elvish/sys/fdset_notfreebsd.go (about) 1 // +build !freebsd,!windows,!plan9 2 3 package sys 4 5 import ( 6 "unsafe" 7 8 "golang.org/x/sys/unix" 9 ) 10 11 var nFdBits = uint(8 * unsafe.Sizeof(unix.FdSet{}.Bits[0])) 12 13 type FdSet unix.FdSet 14 15 func (fs *FdSet) s() *unix.FdSet { 16 return (*unix.FdSet)(fs) 17 } 18 19 func NewFdSet(fds ...int) *FdSet { 20 fs := &FdSet{} 21 fs.Set(fds...) 22 return fs 23 } 24 25 func (fs *FdSet) Clear(fds ...int) { 26 for _, fd := range fds { 27 u := uint(fd) 28 fs.Bits[u/nFdBits] &= ^(1 << (u % nFdBits)) 29 } 30 } 31 32 func (fs *FdSet) IsSet(fd int) bool { 33 u := uint(fd) 34 return fs.Bits[u/nFdBits]&(1<<(u%nFdBits)) != 0 35 } 36 37 func (fs *FdSet) Set(fds ...int) { 38 for _, fd := range fds { 39 u := uint(fd) 40 fs.Bits[u/nFdBits] |= 1 << (u % nFdBits) 41 } 42 } 43 44 func (fs *FdSet) Zero() { 45 *fs = FdSet{} 46 }