Zig Version
0.14.0-dev.2547+77c63ac36
Steps to Reproduce and Observed Behavior
const std = @import("std");
const w = std.os.windows;
extern "kernel32" fn CreateSemaphoreW(
security_attrs: ?*w.SECURITY_ATTRIBUTES,
init_count: i32,
max_count: i32,
name: ?[*:0]const u16,
) callconv(.winapi) ?w.HANDLE;
pub fn main() !void {
// Create an unnamed semaphore
const sem = CreateSemaphoreW(null, 1, 1, null) orelse unreachable;
var buffer: [w.PATH_MAX_WIDE]u16 = undefined;
const result = w.QueryObjectName(sem, &buffer));
// 'isUnnamed' is impossible to implement right now but it really should be
if (isUnnamed(result)) {
std.debug.print("Unamed\n", .{});
} else {
const name = try result;
std.debug.print("Sem name: \"{}\"", .{ std.unicode.fmtUtf16Le(name) });
}
}
Expected Behavior
There should be some way to detect if the handle given to QueryObjectName is for an unnamed object or at the very least it should not return error.Unexpected for a condition this is very much possible (as noted in the QueryObjectName implementation).
The comment mentioned appears to handle it this way because QueryObjectName was originally written (I guess) to support file name lookup; however, the function should not limit itself to this use case as there are other things that can be named besides files and even files are sometimes unnamed, such as anonymous pipes.
Zig Version
0.14.0-dev.2547+77c63ac36
Steps to Reproduce and Observed Behavior
Expected Behavior
There should be some way to detect if the handle given to
QueryObjectNameis for an unnamed object or at the very least it should not returnerror.Unexpectedfor a condition this is very much possible (as noted in theQueryObjectNameimplementation).The comment mentioned appears to handle it this way because
QueryObjectNamewas originally written (I guess) to support file name lookup; however, the function should not limit itself to this use case as there are other things that can be named besides files and even files are sometimes unnamed, such as anonymous pipes.