github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/internal/poll/errno_unix.go (about)

     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 aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
     6  // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
     7  
     8  package poll
     9  
    10  import "syscall"
    11  
    12  // Do the interface allocations only once for common
    13  // Errno values.
    14  var (
    15  	errEAGAIN error = syscall.EAGAIN
    16  	errEINVAL error = syscall.EINVAL
    17  	errENOENT error = syscall.ENOENT
    18  )
    19  
    20  // errnoErr returns common boxed Errno values, to prevent
    21  // allocations at runtime.
    22  func errnoErr(e syscall.Errno) error {
    23  	switch e {
    24  	case 0:
    25  		return nil
    26  	case syscall.EAGAIN:
    27  		return errEAGAIN
    28  	case syscall.EINVAL:
    29  		return errEINVAL
    30  	case syscall.ENOENT:
    31  		return errENOENT
    32  	}
    33  	return e
    34  }