i trying to make syscall open on current directory, i dont understand why it behave differently some one can help me ? 🙂
they both correctly compile with no error
const std = @import("std");
pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
return asm volatile ("syscall"
: [ret] "={rax}" (-> usize),
: [number] "{rax}" (number),
[arg1] "{rdi}" (arg1),
[arg2] "{rsi}" (arg2),
: "rcx", "r11", "memory"
);
}
const O_DIRECTORY = 65536;
pub fn main() void {
const s = ".";
const r : usize = syscall2(2, @ptrToInt(&s), O_DIRECTORY);
std.debug.print("{}\n", .{@bitCast(i64, r)}); // -2
std.debug.print("{}\n", .{std.os.linux.getErrno(r)}); // os.linux.errno.generic.E.NOENT
return;
}
c code
#include <unistd.h>
#include <stdio.h>
#define O_DIRECTORY 65536
int main()
{
int a = syscall(2, ".", 0 | O_DIRECTORY);
printf("%d", a); // 3
}