toStringzNGC

Convert a D string to a C style null terminated pointer

The function uses a static buffer in order to keep the string whie needed. The function's return type is a custom type that tracks the life time of the pointer. This type is implicitly convertible to char* for ease of use.

Most cases can use the return type as if it is a pointer to char:

fcntl.open(toStringzNGC(pathname), flags);

If keeping the pointer around longer is needed, it should be stored in a variable of type auto:

auto fileNameC = toStringzNGC(fileName);

This can be kept around until end of scope. It can be released earlier with the release function:

fileNameC.release();

nothrow @trusted @nogc
toStringzNGC
(
string dString
)

Parameters

dString string

the D string to be converted to zero terminated format.

Return Value

Type: auto

A custom type with a destructor, a function called release(), and an implicit conversion to char*.

Meta