Returns same as toString but also if cstr is not null releases its memory calling release(cast(void*) cstr).
Creates temporary C string with copy of passed text.
Creates C string allocated using tryAllocate with copy of str. If str is null returns null.
Creates GC-allocated string with copy of C string text. If cstr is null returns null, otherwise if cstr is empty returns "".
Returns array representing C string where '\0' character is placed after the end of the array. If cstr is null returns null.
Compare C strings lexicographically.
Returns whether two C strings are equal.
Returns C string length. If cstr is null returns 0.
version(Posix): import core.stdc.stdlib: free; import core.sys.posix.unistd: getcwd; import core.sys.posix.stdlib: getenv, setenv; import std.exception: enforce; @property string cwd() { return enforce(getcwd(null, 0).moveToString!free()); } string getEnvironment(in char[] name) { return enforce(getenv(name.tempCString()).toString()); } void setEnvironment(in char[] name, in char[] value) { enforce(setenv(name.tempCString(), value.tempCString(), 1) != -1); }
version(Windows): import core.sys.windows.windows: SetEnvironmentVariableW; import std.exception: enforce; void setEnvironment(in char[] name, in char[] value) { enforce(SetEnvironmentVariableW(name.tempCString!wchar(), value.tempCString!wchar())); }
Denis Shelomovskij 2013
Helper functions for working with C strings.
This module is intended to provide fast, safe and garbage free way to work with C strings.