From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 3 14:28:27 2010 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F11C71065679 for ; Wed, 3 Feb 2010 14:28:27 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id 608998FC2D for ; Wed, 3 Feb 2010 14:28:27 +0000 (UTC) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id o13ESAHS055342; Wed, 3 Feb 2010 15:28:26 +0100 (CET) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id o13ESATl055341; Wed, 3 Feb 2010 15:28:10 +0100 (CET) (envelope-from olli) Date: Wed, 3 Feb 2010 15:28:10 +0100 (CET) Message-Id: <201002031428.o13ESATl055341@lurza.secnetix.de> From: Oliver Fromme To: freebsd-hackers@FreeBSD.ORG, swehack@gmail.com In-Reply-To: X-Newsgroups: list.freebsd-hackers User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Wed, 03 Feb 2010 15:28:26 +0100 (CET) Cc: Subject: Re: Does getc(3) use the read(2) syscall? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-hackers@FreeBSD.ORG, swehack@gmail.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Feb 2010 14:28:28 -0000 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? > > 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 . -- Tim Peters