3

I would like to read how various libraries are implemented. I looked under /usr/src/include and all I found was .h files. For example, I was looking at malloc.h and all that it does is declare extern functions.

So I am trying to find the source for those functions. I downloaded GCC source RPM, but looking at the GCC source, it looks more like compiler code, rather than code for libraries such as stdlib. Can you please help me by pointing me to the right direction.

2
  • gcc source code should look like 'compiler code', after all, gcc is a compiler. Commented Jun 16, 2011 at 12:36
  • A bit of an aside: malloc.h is legacy compatibility junk that should not be used. The correct header for malloc is stdlib.h. Commented Jun 16, 2011 at 14:05

3 Answers 3

7

You need to get the source code of the associated C library, probably glibc or eglibc in your case.

In the /usr/include/ folder, only the headers of the libc are present, along with some linux kernel headers in the linux/ subfolder.

Sign up to request clarification or add additional context in comments.

Comments

7

You're looking for glibc, rather than gcc.

Comments

3
  • .h files never contains code (well, at least they should. Macros are exceptions)
  • the basic C functions are either in glibc or linux kernel
  • gcc, linux and glibc code are huge beasts, if you are a beginning beginner, you should go for simpler things
  • you probably should take a simple library, one that offer a few tools, on a narrow subject.
  • then go for linux and glibc (or uclibc)

I personnaly learnt many interesting stuff by reading microcontroller system libraries such as http://www.nongnu.org/avr-libc/, but this depends on what you need to do, and it requires a microcontroller to run it.

An idea: depending of what you're looking for, you could go for busybox: it is a reimplementation of many usefull system commands, you can learn a lot from it and running it do not require a dedicated computer.

Update: i asked a question related to glibc functions that got a few very interesting answers from my not-guru p.o.v: where to find select() source code in glibc source?

2 Comments

I found kernel map at makelinux.net/kernel_map to be a good source of how code within kernel is organized
Wow, that kernel map is exactly what i was looking for! thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.