I was wondering where I can find the actual C implementation of atoi() (or other such functions). I looked into stdlib.h but it seems like atoi is not implemented there. Is there a way to view the libc source tree and see the actual C code?
Asked
Active
Viewed 1,057 times
3
-
1Question received a close vote for being off-topic, since whoever cast the vote assumes it's general programming question. I personally would argue that this is still relevant to Ubuntu. `glibc` is essential part of the Ubuntu as operating system, and knowing how certain functions are implemented is essential for developers and learners, and it's partially related to obtaining source code of programs that are standard to Ubuntu. I'd caution against hasty close-voting. – Sergiy Kolodyazhnyy Oct 16 '17 at 05:31
-
@muru yeah, I'd say it's a good fit. Exactly about getting the source code – Sergiy Kolodyazhnyy Oct 16 '17 at 06:19
-
@SergiyKolodyazhnyy Yes, and even for *nonessential* things, asking how to view the source code that is built to produce an Ubuntu package is hardly a general programming question either. – Eliah Kagan Oct 16 '17 at 16:20
2 Answers
4
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
Sergiy Kolodyazhnyy
- 103,293
- 19
- 273
- 492
1
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.
ItM
- 233
- 1
- 7