-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_api.zig
More file actions
44 lines (37 loc) · 1.01 KB
/
Copy pathc_api.zig
File metadata and controls
44 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/// For definitions see root.zig
const re = @import("replace_exe");
const std = @import("std");
const native_os = @import("builtin").os.tag;
export fn self_delete() c_int {
const allocator = std.heap.c_allocator;
re.selfDelete(allocator) catch {
return -1;
};
return 0;
}
export fn self_replace(new_exe_path: [*c]const u8) c_int {
const allocator = std.heap.c_allocator;
const path = std.mem.sliceTo(new_exe_path, 0);
re.selfReplace(allocator, path) catch {
return -1;
};
return 0;
}
export fn self_delete_excluding_path(exclude_path: [*c]const u8) c_int {
const path = std.mem.sliceTo(exclude_path, 0);
re.selfDeleteExcludingPath(switch (native_os) {
.windows => std.heap.c_allocator,
else => null,
}, path) catch {
return -1;
};
return 0;
}
/// Windows only, is a no-op on linux/unix
export fn init() c_int {
switch (native_os) {
.windows => re.init(std.heap.c_allocator),
else => {},
}
return 0;
}