Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the source code from header declaration?

Tags:

c++

c

linux

emacs

I want to browse the source code in of the symbols in my header files in /usr/include/ . For example, in netdb.h, there's a function named getaddrinfo(...). I want to know where the source code is stored at least by using the shell.

I will be more appreciate if you tell me how to do it specifically in Emacs and/or Cscope.

like image 442
Amumu Avatar asked Sep 11 '26 00:09

Amumu


2 Answers

The definition (with the function body) of standard C library's functions is (usually on Linux) inside the GNU Libc. Several functions (those in the section 2 of man pages for syscalls, with syscall numbers listed in <asm/unistd.h>) are tiny wrappers to system calls, so the actual work is done inside the linux kernel whose source is on kernel.org. For instance, write(2) is a system call (mostly done in the kernel) which may be used by the printf(3) library function (whose code is in GNU Libc). You could install GNU Libc source code and use ctags to find symbols there.

The declaration of standard C library's functions are in header files under /usr/include, so utilities like ctags can help you find them.

like image 141
Basile Starynkevitch Avatar answered Sep 12 '26 13:09

Basile Starynkevitch


You can use c-tags.

C-] - go to definition
C-T - Jump back from the definition.
C-W C-] - Open the definition in a horizontal split

like image 35
Alok Save Avatar answered Sep 12 '26 13:09

Alok Save