github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/core/elvish/sys/fdset_freebsd.go (about) 1 // For whatever reason, on FreeBSD the only field of FdSet is called 2 // X__fds_bits; on other Unices it is called Bits. This difference is irrelevant 3 // for C programs, as POSIX defines a set of macros for accessing FdSet, which 4 // hide the underlying difference. However since Elvish does not cgo and relies 5 // on the auto-generated struct definitions, it has to cope with the difference. 6 7 package sys 8 9 import ( 10 "reflect" 11 12 "golang.org/x/sys/unix" 13 ) 14 15 var nFdBits = (uint)(reflect.TypeOf(unix.FdSet{}.X__fds_bits[0]).Size() * 8) 16 17 type FdSet unix.FdSet 18 19 func (fs *FdSet) s() *unix.FdSet { 20 return (*unix.FdSet)(fs) 21 } 22 23 func NewFdSet(fds ...int) *FdSet { 24 fs := &FdSet{} 25 fs.Set(fds...) 26 return fs 27 } 28 29 func (fs *FdSet) Clear(fds ...int) { 30 for _, fd := range fds { 31 u := uint(fd) 32 fs.X__fds_bits[u/nFdBits] &= ^(1 << (u % nFdBits)) 33 } 34 } 35 36 func (fs *FdSet) IsSet(fd int) bool { 37 u := uint(fd) 38 return fs.X__fds_bits[u/nFdBits]&(1<<(u%nFdBits)) != 0 39 } 40 41 func (fs *FdSet) Set(fds ...int) { 42 for _, fd := range fds { 43 u := uint(fd) 44 fs.X__fds_bits[u/nFdBits] |= 1 << (u % nFdBits) 45 } 46 } 47 48 func (fs *FdSet) Zero() { 49 *fs = FdSet{} 50 }