Source file src/internal/poll/errno_unix.go

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build unix || wasip1
     6  
     7  package poll
     8  
     9  import "syscall"
    10  
    11  // Do the interface allocations only once for common
    12  // Errno values.
    13  var (
    14  	errEAGAIN error = syscall.EAGAIN
    15  	errEINVAL error = syscall.EINVAL
    16  	errENOENT error = syscall.ENOENT
    17  )
    18  
    19  // errnoErr returns common boxed Errno values, to prevent
    20  // allocations at runtime.
    21  func errnoErr(e syscall.Errno) error {
    22  	switch e {
    23  	case 0:
    24  		return nil
    25  	case syscall.EAGAIN:
    26  		return errEAGAIN
    27  	case syscall.EINVAL:
    28  		return errEINVAL
    29  	case syscall.ENOENT:
    30  		return errENOENT
    31  	}
    32  	return e
    33  }
    34  

View as plain text