的确,和真正的程序员相比,我差得太远,但和同龄人,同水平的人来说,我还能算点什么的..
如果不是有感来研究Linux的源码,肯定不会发现...原来,竟有这么漂亮的函数定义方式.
#define _syscall0(type,name) \
type name(void) \
{ \
type __res; \
__asm__ volatile ("int $0x80" \
: "=a" (__res) \
: "0" (__NR_##name)); \
if (__res >= 0) \
return __res; \
errno = -__res; \
return -1; \
}
#define _syscall1(type,name,atype,a) \
type name(atype a) \
{ \
type __res; \
__asm__ volatile ("int $0x80" \
: "=a" (__res) \
: "0" (__NR_##name),"b" (a)); \
if (__res >= 0) \
return __res; \
errno = -__res; \
return -1; \
}
#define _syscall2(type,name,atype,a,btype,b) \
type name(atype a,btype b) \
{ \
type __res; \
__asm__ volatile ("int $0x80" \
: "=a" (__res) \
: "0" (__NR_##name),"b" (a),"c" (b)); \
if (__res >= 0) \
return __res; \
errno = -__res; \
return -1; \
}
#define _syscall3(type,name,atype,a,btype,b,ctype,c) \
type name(atype a,btype b,ctype c) \
{ \
type __res; \
__asm__ volatile ("int $0x80" \
: "=a" (__res) \
: "0" (__NR_##name),"b" (a),"c" (b),"d" (c)); \
if (__res<0) \
errno=-__res , __res = -1; \
return __res;\
}
如果能读懂的话,应该理解是什么意思.在unistd.h文件中这几行代码,竟将67个系统函数给概括了(Linux0.01为67,0.95增加为89.)..
我没见过多少比这更精简的代码,我只能说,我的感觉,这不能是一般的漂亮,而是精简到极致的华丽..
....打心底佩服Linus大侠!!