Implement WASI C API.
This commit implements an initial WASI C API that can be used to instantiate and configure a WASI instance from C. This also implements a `WasiBuilder` for the C# API enabling .NET hosts to bind to Wasmtime's WASI implementation.
This commit is contained in:
@@ -63,6 +63,23 @@ namespace Wasmtime.Externs
|
||||
return Encoding.UTF8.GetString(Span.Slice(address, length));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a null-terminated UTF-8 string from memory.
|
||||
/// </summary>
|
||||
/// <param name="address">The zero-based address to read from.</param>
|
||||
/// <returns>Returns the string read from memory.</returns>
|
||||
public string ReadNullTerminatedString(int address)
|
||||
{
|
||||
var slice = Span.Slice(address);
|
||||
var terminator = slice.IndexOf((byte)0);
|
||||
if (terminator == -1)
|
||||
{
|
||||
throw new InvalidOperationException("string is not null terminated");
|
||||
}
|
||||
|
||||
return Encoding.UTF8.GetString(slice.Slice(0, terminator));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a UTF-8 string at the given address.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user