package sys

import (
	
	
	
)

// UnwrapOSError returns an Errno or zero if the input is nil.
func ( error) Errno {
	if  == nil {
		return 0
	}
	 = underlyingError()
	switch  {
	case nil, io.EOF:
		return 0 // EOF is not a Errno
	case fs.ErrInvalid:
		return EINVAL
	case fs.ErrPermission:
		return EPERM
	case fs.ErrExist:
		return EEXIST
	case fs.ErrNotExist:
		return ENOENT
	case fs.ErrClosed:
		return EBADF
	}
	return errorToErrno()
}

// underlyingError returns the underlying error if a well-known OS error type.
//
// This impl is basically the same as os.underlyingError in os/error.go
func underlyingError( error) error {
	switch err := .(type) {
	case *os.PathError:
		return .Err
	case *os.LinkError:
		return .Err
	case *os.SyscallError:
		return .Err
	}
	return 
}