Function openat [src]

Prototype

pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, _: mode_t) usize

Parameters

dirfd: i32path: [*:0]const u8flags: u32_: mode_t

Source

pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, _: mode_t) usize { // we skip perms because only create supports perms if (dirfd == AT.FDCWD) { // openat(AT_FDCWD, ...) == open(...) return open(path, flags); } var dir_path_buf: [std.fs.max_path_bytes]u8 = undefined; var total_path_buf: [std.fs.max_path_bytes + 1]u8 = undefined; const rc = fd2path(dirfd, &dir_path_buf, std.fs.max_path_bytes); if (rc != 0) return rc; var fba = std.heap.FixedBufferAllocator.init(&total_path_buf); var alloc = fba.allocator(); const dir_path = std.mem.span(@as([*:0]u8, @ptrCast(&dir_path_buf))); const total_path = std.fs.path.join(alloc, &.{ dir_path, std.mem.span(path) }) catch unreachable; // the allocation shouldn't fail because it should not exceed max_path_bytes fba.reset(); const total_path_z = alloc.dupeZ(u8, total_path) catch unreachable; // should not exceed max_path_bytes + 1 return open(total_path_z.ptr, flags); }