A D wrapper around a C function Any problems with this D wrapper around libcomcom_run_command() C function from C library libcomcom?

Does it work as expected? Is it idiomatic? Is it the right way to do this?

module libcomcom_wrapper;

import std.string;
import std.algorithm.iteration : map;
import std.array : array;
import std.exception : ErrnoException;
import libcomcom;

string runCommand(string file, string[] argv, string[] envp, string input, int timeout = -1) {
    const(char*) output;
    size_t output_len;
    const char*[] childArgv = map!(s =&gt; s.toStringz)(argv).array;
    const char*[] childEnvp = map!(s =&gt; s.toStringz)(envp).array;
    immutable int res = libcomcom_run_command(input.ptr, input.length,
                                              &amp;output, &amp;output_len,
                                              file.toStringz, childArgv.ptr,
                                              childEnvp.ptr,
                                              timeout);
    if (res != 0) {
        throw new ErrnoException("Run command"); // TODO: Localization
    }
    import core.stdc.stdlib : free;
    scope(exit) free(cast(void*) output);
    return output[0..output_len].idup;
}


The code was taken here.
Nitpick: map!(s =&gt; s.toStringz)(argv) would be more idiomatic as argv.map!toStringz. Apart from that, your code looks very much correct. It should work as expected, and is indeed the way to do this.