Skip to content

Commit

Permalink
implement std.os.Dir for windows
Browse files Browse the repository at this point in the history
improve std.os.File.access so that it does not depend on shlwapi.dll

closes #1084
  • Loading branch information
andrewrk committed Jun 12, 2018
1 parent 0a18d53 commit 3dd9af9
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 102 deletions.
10 changes: 2 additions & 8 deletions doc/docgen.zig
Expand Up @@ -51,14 +51,8 @@ pub fn main() !void {
var toc = try genToc(allocator, &tokenizer);

try os.makePath(allocator, tmp_dir_name);
defer {
// TODO issue #709
// disabled to pass CI tests, but obviously we want to implement this
// and then remove this workaround
if (builtin.os != builtin.Os.windows) {
os.deleteTree(allocator, tmp_dir_name) catch {};
}
}
defer os.deleteTree(allocator, tmp_dir_name) catch {};

try genHtml(allocator, &tokenizer, &toc, &buffered_out_stream.stream, zig_exe);
try buffered_out_stream.flush();
}
Expand Down
18 changes: 15 additions & 3 deletions std/os/file.zig
Expand Up @@ -96,7 +96,20 @@ pub const File = struct {
return File{ .handle = handle };
}

pub fn access(allocator: *mem.Allocator, path: []const u8, file_mode: os.FileMode) !bool {
pub const AccessError = error {
PermissionDenied,
NotFound,
NameTooLong,
BadMode,
BadPathName,
Io,
SystemResources,
OutOfMemory,

Unexpected,
};

pub fn access(allocator: *mem.Allocator, path: []const u8, file_mode: os.FileMode) AccessError!bool {
const path_with_null = try std.cstr.addNullByte(allocator, path);
defer allocator.free(path_with_null);

Expand All @@ -123,8 +136,7 @@ pub const File = struct {
}
return true;
} else if (is_windows) {
// TODO do not depend on shlwapi.dll
if (os.windows.PathFileExistsA(path_with_null.ptr) == os.windows.TRUE) {
if (os.windows.GetFileAttributesA(path_with_null.ptr) != os.windows.INVALID_FILE_ATTRIBUTES) {
return true;
}

Expand Down

0 comments on commit 3dd9af9

Please sign in to comment.