4

I am using Linux (ubuntu).

I want to read the function definitions of some functions which are declared in header files like stdlib.h

I tried looking for stdlib.c but could not find one.

Can anyone please let me know where can i find the corresponding code file on my system.

Forgive me if i am being too naive. Thanks

abhi
  • 3,476
  • 5
  • 41
  • 58
  • possible duplicate of [Where to find stdio.h functions implementations?](http://stackoverflow.com/questions/5233514/where-to-find-stdio-h-functions-implementations) – Fred Foo Feb 22 '13 at 00:56

4 Answers4

6

You need to download the source code for glibc. Your distribution will typically only ship with a compiled version of the C library. See also the Wikipedia article.

(E.g. on Debian-like systems try apt-get source libc6.)

glibc isn't the only C library for Linux-like systems, there exist a couple of "competitors". For example, uClib is a very small alternative intended for embedded applications.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • 1
    It's also worth noting that some implementations of the libc locate the implementation of the functions in a own file for each function. So you don't necessarily find a `stdlib.c`. Maybe you have to look for a `memset.c` for example if you are looking for memset. – junix Feb 22 '13 at 00:06
1

For most Linux-based systems, the standard library is provided by glibc. You can browse the git repository here:

http://sourceware.org/git/?p=glibc.git;a=tree

Note that much of the interesting source is tucked away under the sysdeps tree, particularly sysdeps/unix/sysv/linux and similar.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
0

As the foregoing answers explain, the code for the functions on Linux is included in glibc. If you need the exact code running on your system, that is our only recurse. If you are just interested in how the functions can be implemented, perhaps the best bet is to look at simpler libcs, look at uClibc, the micro libc for embedded use; look for the libc sources for Minix (the original, not the current Minix3); perhaps the one in Plan 9 is also suitable.

vonbrand
  • 11,412
  • 8
  • 32
  • 52
-2

If you used in ubuntu means you run the Cprogram using vim editor.so which header file you want that header file you press the gf in Esc mode. example

      #include<stdio.h>
     you placed in the cursor point s and press the gf then automatically  go to the standard library of stdio.h

                (or)

Change the directory using command

                  cd /usr/include

This directory is contains in all header files

loganaayahee
  • 809
  • 2
  • 8
  • 13