Date: Wed, 3 Feb 2010 15:28:10 +0100 (CET) From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-hackers@FreeBSD.ORG, swehack@gmail.com Subject: Re: Does getc(3) use the read(2) syscall? Message-ID: <201002031428.o13ESATl055341@lurza.secnetix.de> In-Reply-To: <e0e25d5e1002030326p5e0ef0a1q5ebc77a4e1c69b7c@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Stefan Midjich <swehack@gmail.com> 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?
>
> But i would also love it if someone could show me where __sys_read is
> defined.
getc() works like this:
1. The getc() macro can be found in /usr/include/stdio.h,
the getc() function (for threaded programs) can be found
in src/lib/libc/stdio/getc.c.
2. getc() (both the macro and the function) use the __sgetc()
macro defined in stdio.h.
3. The __sgetc() macro either returns a character directly
from the buffer, or it calls the __srget() function to
refill the buffer. All of the stdio functions can be
found in src/lib/libc/stdio/*.
4. The __srget() function calls the __srefill() function,
then returns a character from the newly refilled buffer.
5. The __srefill() function uses the _sread() function to
perform the actual read operation.
6. The _sread() function uses the _read() method from the
FILE struct.
7. The actual value of the _read() method depends on how
the file was opened. If it's a standard file opened
with fopen() or similar, then the _read() method is
initialized to the __sread() function.
8. Finally, the __sread() function calls _read().
9. _read() is simply an alias for the read() syscall; the
definition is in src/lib/libc/include/namespace.h.
So to answer you question:
Yes, getc() uses the read() syscall.
Best regards
Oliver
--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart
FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd
"Python tricks" is a tough one, cuz the language is so clean. E.g.,
C makes an art of confusing pointers with arrays and strings, which
leads to lotsa neat pointer tricks; APL mistakes everything for an
array, leading to neat one-liners; and Perl confuses everything
period, making each line a joyous adventure <wink>.
-- Tim Peters
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002031428.o13ESATl055341>
