为什么 syslog 有两个不同的函数声明?

Why does syslog have two different function declarations?

根据 Linux 手册页 1 and 2,函数 syslog 有两个不同的函数声明如下:

int syslog(int type, char *bufp, int len);

void syslog(int priority, const char *format, ...);

但是,除了 C++,C 中没有函数重载。

如何解释事实?

一个在手册页 (*) 的第 2 节 (syslog(2)) 中定义,因此是一个系统调用。另一个来自第 3 节 (syslog(3)),因此是一个 C 库函数。

所以 "technically" 它们是不同的函数,但恰好具有相同的名称(尽管它们当然是相关的,因为 (3) 正在使用 (2))。

(*) 参见 manual page sections

第一个是系统调用而不是c函数,它被包裹在函数klogctl中,第二个是c函数。

调用系统调用比 simply invoking a function 复杂得多,手册页中的声明只是一个快捷方式,以程序员熟悉的语法向您显示系统调用名称及其期望的参数.