Skip to content

Commit

Permalink
Merge pull request #3486 from WalterBright/rmdirr
Browse files Browse the repository at this point in the history
Range-ify std.file rmdir()
  • Loading branch information
DmitryOlshansky committed Jul 28, 2015
2 parents 9a3f852 + a520b81 commit cc64dc3
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions std/file.d
Expand Up @@ -1904,20 +1904,36 @@ unittest
/****************************************************
Remove directory $(D pathname).
Params:
pathname = Range or string specifying the directory name
Throws: $(D FileException) on error.
*/
void rmdir(in char[] pathname)
void rmdir(R)(R pathname)
if (isInputRange!R && isSomeChar!(ElementEncodingType!R))
{
// Place outside of @trusted block
auto pathz = pathname.tempCString!FSChar();

version(Windows)
{
cenforce(RemoveDirectoryW(pathname.tempCStringW()),
pathname);
static auto trustedRmdir(const(FSChar)* pathz) @trusted
{
return RemoveDirectoryW(pathz);
}
}
else version(Posix)
{
cenforce(core.sys.posix.unistd.rmdir(pathname.tempCString()) == 0,
pathname);
static auto trustedRmdir(const(FSChar)* pathz) @trusted
{
return core.sys.posix.unistd.rmdir(pathz) == 0;
}
}
static if (isNarrowString!R && is(Unqual!(ElementEncodingType!R) == char))
alias pathStr = pathname;
else
string pathStr = null;
cenforce(trustedRmdir(pathz), pathStr, pathz);
}

/++
Expand Down

0 comments on commit cc64dc3

Please sign in to comment.