Obtaining glibc code can be done via apt-get command. Here's basic process done in terminal, which takes no longer than 5 mins:
- Create
glibc-sourcedirectory withmkdir glibc-sourceandcd glibc-source - run
apt-get source glibc - Once
apt-getis done, you'll have 3 files and one directory,glibc-2.23/,glibc_2.23-0ubuntu3.dsc,glibc_2.23-0ubuntu3.debian.tar.xz,glibc_2.23.orig.tar.xz. The file you want isglibc-2.23/stdlib/atoi.c
Videos
Obtaining glibc code can be done via apt-get command. Here's basic process done in terminal, which takes no longer than 5 mins:
- Create
glibc-sourcedirectory withmkdir glibc-sourceandcd glibc-source - run
apt-get source glibc - Once
apt-getis done, you'll have 3 files and one directory,glibc-2.23/,glibc_2.23-0ubuntu3.dsc,glibc_2.23-0ubuntu3.debian.tar.xz,glibc_2.23.orig.tar.xz. The file you want isglibc-2.23/stdlib/atoi.c
Actually found it in the git repo here: https://github.com/lattera/glibc/search?utf8=%E2%9C%93&q=atoi&type=
Leaving this here to help anyone else who might wonder this in the future.
Most linuxes use a libc version named glibc.
The LXR (online cross-reference system) for glibc is e.g. here http://koala.cs.pub.ro/lxr/glibc/ for 2.9 version (link is broken). I must say that something may be not lxr'ed because some sources are generated in the build process, for example - as i can remember - wrappers around a system calls.
Pthreads are in nptl/ folder. Right link to libc sources is http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.bz2 (or change 2.14 to your version)
Update: After closing of koala's lxr, there are:
Metager with glibc: http://code.metager.de/source/xref/gnu/glibc/(Served with Sun's OpenGrok, which was originally used to generate online x-ref for Solaris/OpenSolaris)Google code search (I know that it was closed; but I also know it's other version which is up):
http://code.google.com/codesearch and try to search something glibc-specific
UPD (march 2013) They killed codesearch again:
404. That’s an error.The requested URL /codesearch was not found on this server. That’s all we know.
UPD 2017
Metager with glibc: http://code.metager.de/source/xref/gnu/glibc/There is online git by glibc authors: https://sourceware.org/git/?p=glibc.git (tree is browserable at https://sourceware.org/git/?p=glibc.git;a=tree)
Glibc git is mirrored to github (which has some searching functions) https://github.com/bminor/glibc Buildroot 2018.05 notably uses this mirror.
There is search like google's codesearch in all debian packages: https://codesearch.debian.net/. It can search in glibc sources by "package:glibc request" request and also have file browser: http://sources.debian.net/src/glibc/
Info on the glibc repository: http://sourceware.org/glibc/wiki/GlibcGit
Clone it to get your own copy and search it however you like:
git clone git://sourceware.org/git/glibc.git
I load it up in an IDE project (using whatever preferred IDE) and the code navigation works quite well to let me find what I'm interested in.
Browse the source online http://sourceware.org/git/?p=glibc.git
The POSIX interface of malloc is defined here.
If you want to find out how the C library in GNU/Linux (glibc) implements malloc, go and get the source code from http://ftp.gnu.org/gnu/glibc/ or browse the git repository and look at the malloc/malloc.c file.
There is also the base documentation of the Memory Allocator by Doug Lea that describes the theory of a m(emory)alloc(ator) (read this carrefully, and then decide if you really need to implement your own malloc).
Look in the appropriate release of glibc at the old release site1 or here. For example, if you are using glib 2.9, it is in this archive. Look for the file malloc/malloc.c.
You will see that it is not a trivial piece of library code.
1 It looks like they changed the directory structure after glibc-2.9.