Hello,
I am totally new to Kotlin and I am trying to call the standard posix function execv. The “__argv” argument accepted by this function is an array of C string pointers, with the last element of the array being null.
I can’t find a find to call the function, which is defined as:
platform.posix 11_posix.knm @CCall
public external fun execv(
@CCall.CString
__path: String?,
__argv: CValuesRef<CPointerVar<ByteVar /* = ByteVarOf<Byte> */> /* = CPointerVarOf<CPointer<ByteVarOf<Byte>>> */>?
): Int
I have:
val args: Sequence<String> = ...
val command: String = ...
val argsPlusNull: Sequence<String?> = args.plus(null)
memScoped {
val a = argsPlusNull.toList().toCStringArray(memScope)
if (execv(command, a) ...
}
Here, the toCStringArray call is invalid because the list element type is String? rather than String.
How can I then call execv with the proper “__argv” argument?
Many thanks !