3

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?

ItM
  • 233
  • 1
  • 7
  • 1
    Question 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 Answers2

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:

  1. Create glibc-source directory with mkdir glibc-source and cd glibc-source
  2. run apt-get source glibc
  3. Once apt-get is 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 is glibc-2.23/stdlib/atoi.c
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
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