Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does syslog have two different function declarations?

According to the Linux manual pages 1 and 2, the function syslog has two different function declarations as follows:

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

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

However, other than C++, there is no function overloading in C.

How to explain the fact?

like image 952
xmllmx Avatar asked Nov 29 '25 19:11

xmllmx


2 Answers

One is defined in section 2 (syslog(2)) of the manual pages (*), thus a system call. The other one is from section 3 (syslog(3)) thus a C library function.

So "technically" they are different functions that happen to have the same name (albeit they are related of course, as (3) is using (2)).

(*) See manual page sections.

like image 101
Christian.K Avatar answered Dec 01 '25 09:12

Christian.K


The first is a system call not a c function, it is wrapped in the function klogctl, the second is a c function.

Calling a system call is much more involved than simply invoking a function, the declaration in the man pages is simply a short cut showing you the system call name and the arguments it expects in a syntax that programmers are familiar with.

like image 39
Alan Birtles Avatar answered Dec 01 '25 08:12

Alan Birtles