给定系统调用 write 的包装函数:
ssize_t my_write(int fd, const void *buf, size_t count)
{
long __res;
__asm__ volatile
("int $0x80"
: "=a" (__res)
: "0" (4),"D" ((long)(fd)),"S" ((long)(buf)), "d" ((long)(count))
: "ebx","memory");
if (-125 <= __res && __res < 0)
{
errno = -__res;
__res = -1;
}
return __res;
}
我已经用代码(来自 int main())试过了:
int main() {
my_write(2,"an read error occured\n",26);
return 0;
}
但是它不起作用。知道为什么吗?
谢谢