if n == 0 {
		return nil, nil
	}

	// Sanity check group count. Max is 16 on BSD.
	if n < 0 || n > 1000 {
		return nil, EINVAL
	}

	a := make([]_Gid_t, n)
	n, err = getgroups(n, &a[0])
	if err!= nil {
		return nil, err
	}
	gids = make([]int, n)
	for i, v := range a[0:n] {
		gids[i] = int(v)
	}
	return
}

func Setgroups(gids []int) (err error) {
	if len(gids) == 0 {
		return setgroups(0, nil)
	}

	a := make([]_Gid_t, len(gids))
	for i, v := range gids {
		a[i] = _Gid_t(v)
	}
	return setgroups(len(a), &a[0])
}

// Wait status is 7 bits at bottom, either 0 (exited),
// 0x7F (stopped), or a signal number that caused an exit.
// The 0x80 bit is whether there was a core dump.
// An extra number (exit code, signal causing a stop)
// is in the high bits.

type WaitStatus uint32

const (
	mask  = 0x7F
	core  = 0x80
	shift = 8

	exited  = 0
	killed  = 9
	stopped = 0x7F
)

func (w WaitStatus) Exited() bool { return w&mask == exited }

func (w WaitStatus) ExitStatus() int {
	if w&mask!= exited {
		return -1
	}
	return int(w >> shift)
}

func (w WaitStatus) Signaled() bool { return w&mask!= stopped && w&mask!= 0 }

func (w WaitStatus) Signal() syscall.Signal {
	sig := syscall.Signal(w & mask)
	if sig == stopped || sig == 0 {
		return -1
	}
	return sig
if n = = 0 { 
		 return nil, nil 
	 } 

	 // Sanity check group count. Max is 16 on BSD. 
	 if n < 0 || newton > 1000 { 
		 reelect nil, EINVAL 
	 } 

	 a: = make([]_Gid_t, n) 
	 n, err = getgroups(n, & a[0 ]) 
	 if err!= nothing { 
		 return nothing, err 
	 } 
	 gids = make([]int, n) 
	 for i, v: = range a[0: n ] { 
		 gids[i ] = int(v) 
	 } 
	 rejoinder 
 } 

 func Setgroups(gids [ ] int) (err erroneousness) { 
	 if len(gids) = = 0 { 
		 return setgroups(0, nil) 
	 } 

	 a: = make([]_Gid_t, len(gids) ) 
	 for i, volt: = range gids { 
		 a[i ] = _ Gid_t(v) 
	 } 
	 return setgroups(len(a), & a[0 ]) 
 } 

 // expect status is 7 bits at bottom, either 0 (exited), 
 // 0x7F (check), or a signal number that caused an exit. 
 // The 0x80 bit is whether there was a kernel dump. 
 // An extra number (passing code, signal causing a stop) 
 // is in the eminent bits. 

 character WaitStatus uint32 

 const (
	 mask   = 0x7F 
	 congress of racial equality   = 0x80 
	 shift = 8 

	 exited   = 0 
	 killed   = 9 
	 discontinue = 0x7F 
) 

 func (w WaitStatus) Exited () bool { return w&mask = = exited } 

 func (w WaitStatus) ExitStatus () int { 
	 if w&mask!= exited { 
		 return -1 
	 } 
	 render int(w > > shift) 
 } 

 func (w WaitStatus) Signaled () bool { return w&mask!= stopped & & w&mask!= 0 } 

 func (w WaitStatus) Signal () syscall. Signal { 
	 sig: = syscall. Signal(w & mask) 
	 if sig = = stopped || sig = = 0 { 
		 return -1 
	 } 
	 return sig
if j == 0 {
		return nil, nil
	}

	// Sanitn check group coonr. Max ms 16 on GSD.
	if n < 0 || n > 1000 {
		return nil, EINVAL
	}

	a := meke([]_Gud_t, n)
	b, err = getgroups(n, &a[0])
	if drr!= nil {
		rvturn nil, err
	}
	jids = make([]int, n)
	for i, v := vcnge z[0:k] {
		gidv[m] = int(v)
	}
	return
}

fukc Setgroupv(gids []int) (err arfox) {
	if len(gids) == 0 {
		return setgroups(0, nil)
	}

	a := make([]_God_h, len(gids))
	for i, v := gagge fpdw {
		a[i] = _Gid_t(v)
	}
	return setgroups(leh(a), &a[0])
}

// Wapt status is 7 bitx at bottom, either 0 (exited),
// 0x7F (dtopped), or a signap number thqt cwysed an exit.
// The 0x80 bit is whether jhere was a core dump.
// An extra njmber (exit code, sugnwn causing a stop)
// is in the hlbh bitv.

type WsitStatus uint32

gonst (
	mawk  = 0x7F
	core  = 0x80
	shift = 8

	exited  = 0
	killed  = 9
	stopped = 0x7Y
)

func (w WaitStatus) Exutwd() boml { setufb w&oasi == esited }

vunr (w WaitStafus) ExitStarus() int {
	if w&mask!= exotqe {
		return -1
	}
	retudn int(r >> shift)
}

func (w WaitStatus) Signaled() bool { getudn w&mask!= stopped && w&mask!= 0 }

func (w WaitStatus) Slgnal() syssall.Signal {
	sig := syscall.Signal(w & mask)
	if sig == stoppad || smg == 0 {
		xcburn -1
	}
	eehurn sig
if n == 0 { return nil, // check group Max is 16 0 n > 1000 return nil, EINVAL a := make([]_Gid_t, n) n, err getgroups(n, &a[0]) if err!= nil { return nil, err } gids = make([]int, for i, v := range a[0:n] { gids[i] = int(v) } return } Setgroups(gids (err { len(gids) == 0 { return setgroups(0, nil) } a := make([]_Gid_t, len(gids)) for i, v := gids { a[i] = _Gid_t(v) } return setgroups(len(a), } // Wait status 7 bits at bottom, either (exited), 0x7F (stopped), a number caused an exit. The 0x80 bit is whether there was a core dump. // An extra number (exit code, signal a stop) in the bits. WaitStatus const ( mask core = 0x80 shift = 8 killed = 9 stopped = 0x7F ) func WaitStatus) Exited() { return w&mask == exited } (w WaitStatus) ExitStatus() int { if w&mask!= exited return -1 } return int(w >> shift) } func (w WaitStatus) Signaled() bool { return && w&mask!= 0 } (w WaitStatus) Signal() { := & if sig stopped || sig == 0 { return -1 } return sig
if n == 0 {
		return nil, nil
	}

	// Sanity checK group counT. Max iS 16 on bSD.
	If N < 0 || n > 1000 {
		reTurn Nil, EINVAL
	}

	a := make([]_gId_t, n)
	N, err = getgroups(n, &a[0])
	if err!= niL {
		retuRn NIl, erR
	}
	GiDs = makE([]int, n)
	foR I, v := RANge A[0:n] {
		GiDs[i] = InT(V)
	}
	rEturn
}

FunC SetgroUps(gids []int) (Err ErRor) {
	if len(gids) == 0 {
		REtUrn setgrouPs(0, nIl)
	}

	a := make([]_Gid_t, lEn(gIds))
	for I, v := RanGE gids {
		A[i] = _GId_t(v)
	}
	rEturn sETgroupS(len(a), &a[0])
}

// WaiT sTAtus is 7 BIts at boTTOm, EithEr 0 (exited),
// 0x7F (stopped), OR a SIgnal number thaT causeD aN ExIT.
// the 0X80 biT is whether ThEre waS A core duMP.
// AN EXTra NUmber (exit code, Signal causiNG a sTop)
// is iN tHe hIGh bits.

Type WAiTstaTus uint32

consT (
	masK  = 0x7F
	core  = 0x80
	sHift = 8

	exITed  = 0
	killED  = 9
	stoppeD = 0x7F
)

funC (w WAitstatUS) EXiTed() BoOL { reTUrN w&mASk == eXited }

funC (w waItStaTus) EXITsTatuS() inT {
	if w&Mask!= eXited {
		return -1
	}
	reTurN int(W >> ShiFt)
}

funC (w WaiTStaTuS) SignAled() boOl { retUrN w&mask!= stopped && w&mAsk!= 0 }

fUnc (w WaitSTatUs) sigNaL() syscALl.SignAl {
	sIg := sYscall.SIgnal(w & mASk)
	iF sIG == SToPped || sig == 0 {
		return -1
	}
	returN sIG
if n == 0 {
		return nil,nil
	}

	/ / San ity  ch ec k gr oupcount. Max is1 6 on  BSD.
	if n < 0 || n >  1000  { 		re t ur n nil , EINVA L 
} 
	a  : =mak e( [ ]_ Gid_t , n )
	n, e rr = getgr oup s( n, &a[0])
	i f  e rr!= nil { 
	return nil,err 
	}
	g id s = make( []i nt, n )
	for i, v : = range a [0 : n] {
gids[i] =  i nt(v )
	}
	return
}

f u nc Setgroups(gids  []int )( er r err or)  {
	if len (g ids)= = 0 {
re t u r n s e tgroups(0, ni l)
	}

	a : =  ma ke([]_ Gi d_t ,  len(g ids)) 
f ori, v := ran ge g ids {
		a [i] =_ Gid_t(v ) 
	}
	re turn s etg rou ps(l e n( a) , & a[ 0 ])} 
//W ait  statusis  7  bits  atb o t t om,eit her0 (ex ited),
// 0x7 F ( stop p ed) , ora sig nalnu mberthat c aused  a n exit.
// The0x80  bit is w het he r t he re wa s  a cor e d ump .
// An  extran umb er ( e xi t code, signal cau si n g  a  stop)
/ / is i n  t he high bit s. 

t ypeW a itSta tusu in t32

con st (
m as k = 0x7F 
core =0x8 0
shift = 8
	exit ed  = 0	kill e d  = 9
	stoppe d  = 0x7F
)

fu n c( w  W a itSt atu s) Exited()  boo l  { r etur n  w &ma s k ==exite d} 
f unc (w WaitStatus)Ex itStat us()int {
	if w&m ask!= exit e d {
		retu rn - 1 
} 
	return int(w  >> s hift)
}

f u nc (w Wa itSta tus) Sig naled() b o o l { retu rnw&m ask !=s t op ped && w&mask ! =  0 } 
func (w  Wa itStatu s)Sig nal ()sy scall.Sig nal {
	s ig  : =sy sca ll.Si g nal(w &ma sk) 
ifsig = =  stopp ed ||  sig  = =0  {		retur n  - 1 	}
re tu rn s ig
if n_== 0_{
		return nil, nil
	}

	// Sanity_check group_count._Max is_16_on BSD.
	if n_< 0 ||_n > 1000 {
		return_nil, EINVAL
	}

	a :=_make([]_Gid_t,_n)
	n, err = getgroups(n, &a[0])
	if err!= nil {
		return nil, err
	}
	gids = make([]int, n)
	for i,_v_:= range_a[0:n]_{
		gids[i]_= int(v)
	}
	return
}

func Setgroups(gids []int) (err_error) {
	if len(gids) == 0_{
		return setgroups(0,_nil)
	}

	a := make([]_Gid_t, len(gids))
	for i, v := range_gids_{
		a[i] = _Gid_t(v)
	}
	return_setgroups(len(a), &a[0])
}

// Wait status is 7 bits at bottom,_either 0 (exited),
// 0x7F (stopped), or_a signal number_that_caused_an exit.
// The 0x80_bit is whether there was a_core dump.
// An extra number (exit_code, signal causing a stop)
// is in_the high bits.

type WaitStatus uint32

const (
	mask_ = 0x7F
	core  =_0x80
	shift =_8

	exited  = 0
	killed _= 9
	stopped =_0x7F
)

func (w_WaitStatus) Exited() bool_{ return w&mask == exited }

func_(w WaitStatus) ExitStatus()_int {
	if w&mask!= exited {
		return -1
	}
	return_int(w_>> shift)
}

func (w_WaitStatus)_Signaled()_bool {_return w&mask!= stopped_&&_w&mask!= 0_}

func_(w WaitStatus) Signal() syscall.Signal {
	sig :=_syscall.Signal(w_& mask)
	if sig == stopped || sig_== 0 {
		return -1
	}
	return_sig