wasi-module-sdk-go/exec/lookup.go

43 lines
926 B
Go

package exec
import (
"errors"
"fmt"
"code.icb4dc0.de/buildr/wasi-module-sdk-go/mem"
rpcv1 "code.icb4dc0.de/buildr/wasi-module-sdk-go/protocol/generated/rpc/v1"
)
func LookPath(file string) (string, error) {
lookupPathReq := &rpcv1.LookupPathRequest{
Command: file,
}
data, err := lookupPathReq.MarshalVT()
if err != nil {
return "", err
}
result := _lookPath(mem.DataToManagedPtr(data))
if result == 0 {
return "", fmt.Errorf("failed to lookup in path: %s", file)
}
resultPtr := uint32(result >> 32)
resultSize := uint32(result)
if resultSize == 0 {
return "", fmt.Errorf("failed to lookup in path: %s", file)
}
lookupPathResp := new(rpcv1.LookupPathResponse)
if err := lookupPathResp.UnmarshalVT(mem.PtrToData(resultPtr, resultSize)); err != nil {
return "", err
}
if len(lookupPathResp.Error) > 0 {
return "", errors.New(lookupPathResp.Error)
}
return lookupPathResp.Path, nil
}