LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-21-2010, 07:05 PM   #1
oscaringolilingo
Member
 
Registered: Dec 2010
Posts: 34

Rep: Reputation: 3
Where to find the source code of _IO_putc_unlocked (c, _IO_stdout); ?


Hi, I'm new here, and well, I thought I might as well just cut to the chase regarding my own programming questions about linux. I am sorry if this strikes someone as rude and I'll try my best to answer other peoples questios to be proactive with this website.

Anyway, I posted this same question a while ago at yahoo answers (http://answers.yahoo.com/question/in...1163451AAjo5Xl) and still am waiting for a response, but I thought that might not have been the best place to put is so, the matter is this:

I was browsing for the source code of printf() from glibc ( http://ftp.gnu.org/gnu/glibc/glibc-2.8.tar.gz ) and in the file printf.c I discovered printf uses putc to print characters on screen, well, I checked the source code of putc in putc.c and found out it uses some strange function _IO_putc_unlocked (c, _IO_stdout); but I can't seem to find the source code for this function. Could anyone please tell me where to find this so I can finally understand the ultimate inner workings of printf?

BTW, here are the source codes of printf.c

Quote:
/* Copyright (C) 1991, 1995, 1996, 1997, 2001, 2004, 2006
Free Software Foundation, Inc.
This file is part of the GNU C Library.

The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

#include <libioP.h>
#include <stdarg.h>
#include <stdio.h>

#undef printf

/* Write formatted output to stdout from the format string FORMAT. */
/* VARARGS1 */
int
__printf (const char *format, ...)
{
va_list arg;
int done;

va_start (arg, format);
done = vfprintf (stdout, format, arg);
va_end (arg);

return done;
}

#undef _IO_printf
ldbl_strong_alias (__printf, printf);
/* This is for libg++. */
ldbl_strong_alias (__printf, _IO_printf);
and of putc.c

Quote:
/* Copyright (C) 1991, 1995, 1996, 1997, 1998, 2002, 2003
Free Software Foundation, Inc.
This file is part of the GNU C Library.

The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

#include "libioP.h"
#include "stdio.h"

#undef _IO_putc

int
_IO_putc (c, fp)
int c;
_IO_FILE *fp;
{
int result;
CHECK_FILE (fp, EOF);
_IO_acquire_lock (fp);
result = _IO_putc_unlocked (c, fp);
_IO_release_lock (fp);
return result;
}
INTDEF(_IO_putc)

#undef putc

#ifdef weak_alias
weak_alias (_IO_putc, putc)

#ifndef _IO_MTSAFE_IO
#undef putc_unlocked
weak_alias (_IO_putc, putc_unlocked)
#endif
#endif
SORRY! I ment http://ftp.gnu.org/gnu/glibc/glibc-2.8.tar.gz not http://ftp.gnu.org/gnu/glibc/glibc-2.9.tar.gz

And apparently printf.c uses vprintf.c, which uses vfprintf.c, which uses putc.c

Last edited by oscaringolilingo; 12-21-2010 at 07:24 PM.
 
Old 12-21-2010, 08:05 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
The source (it's a macro) is in

libio/libio.h

file - 'grep -r ....' is your friend.
 
Old 12-21-2010, 09:24 PM   #3
oscaringolilingo
Member
 
Registered: Dec 2010
Posts: 34

Original Poster
Rep: Reputation: 3
I found what I was looking for here http://hostilefork.com/2010/03/14/wh...eets-the-road/

Thanks to Ratchetr from yahoo answers for that one.

And thank you also, Sergei.

Last edited by oscaringolilingo; 12-21-2010 at 10:06 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where in the source code do I find the source for the Cisco FCoE HBA Drvr? madcowtricks Slackware 6 01-27-2011 03:00 PM
[SOLVED] why I couldn't find the source code of printf function in glibc source? famsinyi Programming 5 09-21-2009 09:06 AM
how to find mv's source code? iclinux Programming 2 02-16-2005 09:17 PM
Where can I find the kwrite source code? BluePyre Programming 2 05-31-2004 05:52 PM
Where can i find source code rajaryan Linux - Newbie 2 03-27-2003 06:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration