Does getc(3) use the read(2) syscall?

Andrey Simonenko simon at
Wed Feb 3 14:04:11 UTC 2010


On Wed, Feb 03, 2010 at 12:26:02PM +0100, Stefan Midjich wrote:
> I'm having trouble looking this function up in the source tree, the trail
> seems to end at __sys_read which has a bunch of prototypes but i can't find
> the actual function code.
> So my question is primarily, does getc use the read system call eventually?

The easiest way is to write a simple program with this function and
run it under ktrace and verify all calls in the output of kdump.

> But i would also love it if someone could show me where __sys_read is
> defined.

Quick check of the path gave me the following:
getc -> __sgetc -> __srget -> __srefill -> _sread ->
     [._read ] -> __sread -> _read

Look how Assembler files for system calls invocations are generated in
the lib/libc/sys/ file, and look at macro variables defined
in the amd64/SYS.h file.  If you understand the idea, then check read.S
file in the <obj>/lib/libc/ directory and the output of "nm read.So".

Declaration of _read() in libc/stdio/stdio.c is done by a trick with
two header files namespace.h included before and un-namespace.h included
after another header files.

Looks like that __sys_read in libc/ is used in directories with thread
code and prototype for __sys_read is defined there.

More information about the freebsd-hackers mailing list