user1261015
user1261015

Reputation:

What is GLIBC? What is it used for?

I was searching for the source code of the C standard libraries. What I mean with it is, for example, how are cos, abs, printf, scanf, fopen, and all the other standard C functions written, I mean to see their source code.

So while searching for this, I came across with GLIBC, but I don't know what it actually is. It is GNU C Library, and it contains some source codes, but what are they actually, are they the source code of the standard functions or are they something else? And what is it used for?

Upvotes: 76

Views: 86517

Answers (5)

"Hands-on" points of view

Upvotes: 5

Aftnix
Aftnix

Reputation: 4589

It's the implementation of Standard C library described in C standards, plus some extras which are not strictly standard but used frequently.

Its main contents are:

  1. C library described in ANSI, C99, C11, C23 standards. It includes macros, symbols, function implementations, etc., such as printf(), malloc(), etc.)

  2. POSIX standard library. The "userland" glue of system calls. (open(), read(), etc.) Actually glibc does not "implement" system calls; the kernel does it. But glibc provides the user land interface to the services provided by kernel so that user application can use a system call just like a ordinary function.

  3. Also some nonstandard but useful stuff.

"use the force, read the source "

$ git clone git://sourceware.org/git/glibc.git

(I was recently pretty enlightened when I looked through malloc.c in glibc)

Upvotes: 85

Sandy
Sandy

Reputation: 121

The glibc package contains standard libraries which are used by multiple programs on the system. In order to save disk space and memory, as well as to make upgrading easier, common system code iskept in one place and shared between programs. This particular package contains the most important sets of shared libraries: the standard C library and the standard math library. Without these two libraries, a Linux system will not function. The glibc package also contains national language (locale) support.

Upvotes: 12

jforberg
jforberg

Reputation: 6752

There are several implementations of the standard. Glibc is the implementation that most Linuxes use, but there are others. Glibc also contains (as Aftnix states) the glue functions which set up the scene for jumps into the kernel (also known as system calls). So many of glibc's 'functions' don't do the actual work but only delegate to the kernel.

To read the source of Glibc, just google for it. There are myriad sites which carry it, and also several variations.

Windows uses Microsoft's own implementation, which I believe is called MSVCR.DLL. I doubt that you will find the source code to that library anywhere. Also note that some functions which a Linux hacker might think of as 'standard', simply don't exist on Windows (notably fork). The reverse is also true.

Other systems will have their own libc.

Upvotes: 16

user529758
user529758

Reputation:

Yes, It's the implementation of standard library functions.

More specifically, it is the implementation for all GNU systems and in almost all *NIX systems that use the Linux kernel.

Upvotes: 3

Related Questions