POSIX link() syscall only takes two arguments (no flags)
The signature is documented as:
int link(const char *, const char *);
(see https://man7.org/linux/man-pages/man2/link.2.html or https://man.netbsd.org/link.2)
And its not some Linux extension, the [syscall
implementation](21b136cc63/fs/namei.c (L4794-L4797))
only expects two arguments too.
It probably *should* have a flags parameter, but its too late now.
I am a bit surprised that linking glibc or musl against code that invokes
a 'link' with three parameters doesn't fail (at least, I couldn't get any
local test cases to trigger a compile or link error).
The test case in std/posix/test.zig is currently disabled, but if I
manually enable it, it works with this change.
This commit is contained in:
committed by
Andrew Kelley
parent
979fd12be9
commit
4d6429fc4f
@@ -1339,13 +1339,12 @@ pub fn tgkill(tgid: pid_t, tid: pid_t, sig: i32) usize {
|
||||
return syscall3(.tgkill, @as(usize, @bitCast(@as(isize, tgid))), @as(usize, @bitCast(@as(isize, tid))), @as(usize, @bitCast(@as(isize, sig))));
|
||||
}
|
||||
|
||||
pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize {
|
||||
pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8) usize {
|
||||
if (@hasField(SYS, "link")) {
|
||||
return syscall3(
|
||||
return syscall2(
|
||||
.link,
|
||||
@intFromPtr(oldpath),
|
||||
@intFromPtr(newpath),
|
||||
@as(usize, @bitCast(@as(isize, flags))),
|
||||
);
|
||||
} else {
|
||||
return syscall5(
|
||||
@@ -1354,7 +1353,7 @@ pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize {
|
||||
@intFromPtr(oldpath),
|
||||
@as(usize, @bitCast(@as(isize, AT.FDCWD))),
|
||||
@intFromPtr(newpath),
|
||||
@as(usize, @bitCast(@as(isize, flags))),
|
||||
0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user