my.cstring

Helper functions for working with C strings.

This module is intended to provide fast, safe and garbage free way to work with C strings.

Members

Aliases

tempCStringW
alias tempCStringW = tempCString!(WCHAR, const(char)[])
Undocumented in source.

Functions

tempCString
auto tempCString(From str)

Creates temporary 0-terminated C string with copy of passed text.

Examples

version (Posix) {
    import core.stdc.stdlib : free;
    import core.sys.posix.stdlib : setenv;
    import std.exception : enforce;

    void setEnvironment(scope const(char)[] name, scope const(char)[] value) {
        enforce(setenv(name.tempCString(), value.tempCString(), 1) != -1);
    }
}

version (Windows) {
    import core.sys.windows.winbase : SetEnvironmentVariableW;
    import std.exception : enforce;

    void setEnvironment(scope const(char)[] name, scope const(char)[] value) {
        enforce(SetEnvironmentVariableW(name.tempCStringW(), value.tempCStringW()));
    }
}

Meta

Authors

Denis Shelomovskij