Pavunkumar
Pavunkumar

Reputation: 5335

How does C compiler decide whether to call library function or system call

I know that read is system call. But when I read man 2 and man 3 of read it shows me different explanation. So , I am suspecting that read has library function and system call. In such case if I use read in my c program, whether compiler will consider read as library function or system call Please explain me on this confusion.

Upvotes: 0

Views: 330

Answers (2)

Fred Foo
Fred Foo

Reputation: 363577

I'm assuming you're on Linux. On that platform, the manpage read(2) describes the Linux system call, while read(3) describes the POSIX specification for read, if you have the POSIX manpages installed. The latter is in category 3 because POSIX doesn't specify a difference between system calls and library functions.

There's only one read in libc, which is (a thin wrapper around) the system call.

Upvotes: 2

user149341
user149341

Reputation:

It doesn't. System calls are present in libc (the C standard library) just like library functions are. The implementations of system calls in libc are just "stubs" which invoke system-specific methods of calling into the kernel.

Upvotes: 6

Related Questions