github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/testutil/testutil_posix.go (about)

     1  // Copyright 2020 the u-root 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 !plan9
     6  // +build !plan9
     7  
     8  package testutil
     9  
    10  import (
    11  	"fmt"
    12  	"os/exec"
    13  	"syscall"
    14  )
    15  
    16  func exitStatus(exitErr *exec.ExitError) (int, error) {
    17  	ws, ok := exitErr.Sys().(syscall.WaitStatus)
    18  	if !ok {
    19  		return 0, fmt.Errorf("sys() is not a syscall WaitStatus: %v", exitErr)
    20  	}
    21  	return ws.ExitStatus(), nil
    22  }