// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || (js && wasm) || wasip1 || windows

package poll

import (
	
	
)

// eofError returns io.EOF when fd is available for reading end of
// file.
func ( *FD) ( int,  error) error {
	if  == 0 &&  == nil && .ZeroReadIsEOF {
		return io.EOF
	}
	return 
}

// Shutdown wraps syscall.Shutdown.
func ( *FD) ( int) error {
	if  := .incref();  != nil {
		return 
	}
	defer .decref()
	return syscall.Shutdown(.Sysfd, )
}

// Fchown wraps syscall.Fchown.
func ( *FD) (,  int) error {
	if  := .incref();  != nil {
		return 
	}
	defer .decref()
	return ignoringEINTR(func() error {
		return syscall.Fchown(.Sysfd, , )
	})
}

// Ftruncate wraps syscall.Ftruncate.
func ( *FD) ( int64) error {
	if  := .incref();  != nil {
		return 
	}
	defer .decref()
	return ignoringEINTR(func() error {
		return syscall.Ftruncate(.Sysfd, )
	})
}

// RawControl invokes the user-defined function f for a non-IO
// operation.
func ( *FD) ( func(uintptr)) error {
	if  := .incref();  != nil {
		return 
	}
	defer .decref()
	(uintptr(.Sysfd))
	return nil
}

// ignoringEINTR makes a function call and repeats it if it returns
// an EINTR error. This appears to be required even though we install all
// signal handlers with SA_RESTART: see #22838, #38033, #38836, #40846.
// Also #20400 and #36644 are issues in which a signal handler is
// installed without setting SA_RESTART. None of these are the common case,
// but there are enough of them that it seems that we can't avoid
// an EINTR loop.
func ignoringEINTR( func() error) error {
	for {
		 := ()
		if  != syscall.EINTR {
			return 
		}
	}
}

// ignoringEINTR2 is ignoringEINTR, but returning an additional value.
func ignoringEINTR2[ any]( func() (, error)) (, error) {
	for {
		,  := ()
		if  != syscall.EINTR {
			return , 
		}
	}
}