-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0831fdd
commit 0225470
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const lib = b.addStaticLibrary(.{ | ||
.name = "znvim", | ||
.root_source_file = b.path("src/znvim.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
b.installArtifact(lib); | ||
|
||
const lib_unit_tests = b.addTest(.{ | ||
.root_source_file = b.path("src/znvim.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); | ||
|
||
const test_step = b.step("test", "Run unit tests"); | ||
test_step.dependOn(&run_lib_unit_tests.step); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.{ | ||
.name = "znvim", | ||
.version = "0.0.0", | ||
.minimum_zig_version = "0.12.0", | ||
.dependencies = .{ | ||
.@"zig-msgpack" = .{ | ||
.url = "https://github.com/zigcc/zig-msgpack/archive/refs/tags/0.0.4.tar.gz", | ||
.hash = "12204ec362b0784a04825021b1bab2fe62d062db5f07052207363a835af7613bb12e", | ||
}, | ||
}, | ||
.paths = .{ | ||
"", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! this is for window's named pipe | ||
//! more info: | ||
//! https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/ | ||
|
||
const std = @import("std"); | ||
const windows = std.os.windows; | ||
const LPCWSTR = windows.LPCWSTR; | ||
const DWORD = windows.DWORD; | ||
const BOOL = windows.BOOL; | ||
const WINAPI = windows.WINAPI; | ||
|
||
/// Waits until either a time-out interval elapses or an instance of the specified named pipe is available for connection | ||
/// (that is, the pipe's server process has a pending ConnectNamedPipe operation on the pipe). | ||
extern "kernel32" fn WaitNamedPipeW( | ||
lpNamedPipeName: LPCWSTR, | ||
nTimeOut: DWORD, | ||
) callconv(WINAPI) BOOL; | ||
|
||
/// this function will try to connect named pipe on windows | ||
/// no need to free the mem | ||
pub fn connectNamedPipe(path: []const u8, allocator: std.mem.Allocator) !std.fs.File { | ||
var arena = std.heap.ArenaAllocator.init(allocator); | ||
defer arena.deinit(); | ||
const arena_allocator = arena.allocator(); | ||
|
||
const utf16_path = try std.unicode.utf8ToUtf16LeWithNull(arena_allocator, path); | ||
const handle = windows.kernel32.CreateFileW( | ||
utf16_path, | ||
windows.GENERIC_READ | windows.GENERIC_WRITE, | ||
0, | ||
null, | ||
windows.OPEN_EXISTING, | ||
0, | ||
null, | ||
); | ||
if (handle == windows.INVALID_HANDLE_VALUE) { | ||
return windows.unexpectedError(windows.kernel32.GetLastError()); | ||
} | ||
|
||
return std.fs.File{ | ||
.handle = handle, | ||
}; | ||
} |
Empty file.
Empty file.