Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ziglang/zig
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0307dc0b774d
Choose a base ref
...
head repository: ziglang/zig
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 61d715d784f3
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Oct 14, 2017

  1. Copy the full SHA
    ad6eec9 View commit details
  2. Copy the full SHA
    61d715d View commit details
Showing with 44 additions and 18 deletions.
  1. +1 −1 std/cstr.zig
  2. +23 −1 std/os/index.zig
  3. +17 −14 std/os/windows/index.zig
  4. +3 −2 std/os/windows/util.zig
2 changes: 1 addition & 1 deletion std/cstr.zig
Original file line number Diff line number Diff line change
@@ -45,5 +45,5 @@ pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) -> %[]u8 {
const result = %return allocator.alloc(u8, slice.len + 1);
mem.copy(u8, result, slice);
result[slice.len] = 0;
return result[0..slice.len];
return result;
}
24 changes: 23 additions & 1 deletion std/os/index.zig
Original file line number Diff line number Diff line change
@@ -322,7 +322,7 @@ pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap)

pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) {
for (envp_buf) |env| {
const env_buf = if (env) |ptr| cstr.toSlice(ptr) else break;
const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break;
allocator.free(env_buf);
}
allocator.free(envp_buf);
@@ -490,6 +490,28 @@ test "os.getCwd" {
}

pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void {
if (is_windows) {
return symLinkWindows(allocator, existing_path, new_path);
} else {
return symLinkPosix(allocator, existing_path, new_path);
}
}

pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void {
const existing_with_null = %return cstr.addNullByte(allocator, existing_path);
defer allocator.free(existing_with_null);
const new_with_null = %return cstr.addNullByte(allocator, new_path);
defer allocator.free(new_with_null);

if (windows.CreateSymbolicLinkA(existing_with_null.ptr, new_with_null.ptr, 0) == 0) {
const err = windows.GetLastError();
return switch (err) {
else => error.Unexpected,
};
}
}

pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void {
const full_buf = %return allocator.alloc(u8, existing_path.len + new_path.len + 2);
defer allocator.free(full_buf);

31 changes: 17 additions & 14 deletions std/os/windows/index.zig
Original file line number Diff line number Diff line change
@@ -25,6 +25,9 @@ pub extern "kernel32" stdcallcc fn CreateProcessA(lpApplicationName: ?LPCSTR, lp
dwCreationFlags: DWORD, lpEnvironment: ?LPVOID, lpCurrentDirectory: ?LPCSTR, lpStartupInfo: &STARTUPINFOA,
lpProcessInformation: &PROCESS_INFORMATION) -> BOOL;

pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(lpSymlinkFileName: LPCSTR, lpTargetFileName: LPCSTR,
dwFlags: DWORD) -> BOOLEAN;

pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> bool;

pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn;
@@ -74,34 +77,34 @@ pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lp

pub const PROV_RSA_FULL = 1;

pub const UNICODE = false;
pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
pub const LPWSTR = &WCHAR;
pub const LPSTR = &CHAR;
pub const CHAR = u8;
pub const PWSTR = &WCHAR;
pub const SIZE_T = usize;

pub const BOOL = bool;
pub const BOOLEAN = BYTE;
pub const BYTE = u8;
pub const WORD = u16;
pub const CHAR = u8;
pub const DWORD = u32;
pub const FLOAT = f32;
pub const HANDLE = &c_void;
pub const HINSTANCE = &@OpaqueType();
pub const HCRYPTPROV = ULONG_PTR;
pub const LPCTSTR = &const TCHAR;
pub const HINSTANCE = &@OpaqueType();
pub const INT = c_int;
pub const LPBYTE = &BYTE;
pub const LPCSTR = &const CHAR;
pub const LPCTSTR = &const TCHAR;
pub const LPCVOID = &const c_void;
pub const LPDWORD = &DWORD;
pub const LPSTR = &CHAR;
pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
pub const LPVOID = &c_void;
pub const LPWSTR = &WCHAR;
pub const PVOID = &c_void;
pub const PWSTR = &WCHAR;
pub const SIZE_T = usize;
pub const TCHAR = if (UNICODE) WCHAR else u8;
pub const UINT = c_uint;
pub const INT = c_int;
pub const ULONG_PTR = usize;
pub const UNICODE = false;
pub const WCHAR = u16;
pub const LPCVOID = &const c_void;
pub const LPBYTE = &BYTE;
pub const WORD = u16;

/// The standard input device. Initially, this is the console input buffer, CONIN$.
pub const STD_INPUT_HANDLE = @maxValue(DWORD) - 10 + 1;
5 changes: 3 additions & 2 deletions std/os/windows/util.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("../../index.zig");
const os = std.os;
const windows = std.os.windows;
const assert = std.debug.assert;
const mem = std.mem;
@@ -75,9 +76,9 @@ error PipeBusy;
/// size buffer is too small, and the provided allocator is null, ::error.NameTooLong is returned.
/// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_mode: windows.DWORD,
creation_disposition: windows.DWORD, flags_and_attrs: windows.DWORD, allocator: ?&Allocator) -> %windows.HANDLE
creation_disposition: windows.DWORD, flags_and_attrs: windows.DWORD, allocator: ?&mem.Allocator) -> %windows.HANDLE
{
var stack_buf: [max_noalloc_path_len]u8 = undefined;
var stack_buf: [os.max_noalloc_path_len]u8 = undefined;
var path0: []u8 = undefined;
var need_free = false;
defer if (need_free) (??allocator).free(path0);