Questions tagged [libc]

The C standard library consists of a set of sections of the ISO C standard which describe a collection of headers and library routines used to implement common operations, such as input/output and string handling, in the C programming language.

The C standard library consists of a set of sections of the ISO C standard which describe a collection of headers and library routines used to implement common operations, such as input/output and string handling, in the C programming language.

There are many implementations of libc with different resource requirements, security goals, etc. With a typical tool chain the libc, compiler and OS work together to achieve some ISO, Posix or custom features/standards. Some libc implementation are only a subset of the ISO standard, but still full featured enough to be used in many applications.

Specific libc tags:

  • - the full Gnu Libc found on most GCC installs.
  • - a smaller micro-controller libc for resource constrained devices
  • - Android libc
  • - unhosted libc
  • - more modern lighter foot print libc

Websites

See also:

Do not confuse with , which is for the C++ programming language.

1076 questions
5
votes
1 answer

What is the purpose of glibc's atomic_forced_read function?

I am trying to understand the purpose of the definition of atomic_forced_read which shows up frequently in the GNU libc implementation of malloc.c. I am not great when it comes to inline assembly, but it looks like this returns the exact same value,…
mreff555
  • 1,049
  • 1
  • 11
  • 21
5
votes
3 answers

Why are many system calls (getpid) captured only once using strace?

I invoked getpid() in a program for many times (to test the efficiency of system calls), however when I use strace to get the trace, only one getpid() call is captured. The code is simple: #include #include #include…
Infinite
  • 3,198
  • 4
  • 27
  • 36
5
votes
1 answer

Linking a program using printf with ld?

I'm getting a undefined reference to _printf when building an assembly program that defines its own _start instead of main, using NASM on x86-64 Ubuntu Build commands: nasm -f elf64 hello.asm ld -s -o hello hello.o hello.o: In function…
Fred Rogers
  • 91
  • 1
  • 3
5
votes
1 answer

Why does gcc/clang know to link to libc by default?

When I run clang/gcc to compile a .c file, I don't need to explicitly link to libc. But it still works as libc and two additional libraries are automatically linked. Why does gcc/clang know to link automatically? Where is this behavior mentioned? $…
user1424739
  • 11,937
  • 17
  • 63
  • 152
5
votes
2 answers

Is there any libc project that does not requires linux kernel

I am using a custom user space environment that has barely no OS support: only one char device, mass storage interface and a single network socket. To provide C programming to this platform, I need a libc. Is there any libc project that is…
Laurent G
  • 2,994
  • 1
  • 18
  • 10
5
votes
2 answers

gets() function and '\0' zero byte in input

Will the gets() function from C language (e.g. from glibc) stop, if it reads a zero byte ('\0') from the file ? Quick test: echo -ne 'AB\0CDE' Thanks. PS this question arises from comments in this question: return to libc - problem PPS the gets…
osgx
  • 90,338
  • 53
  • 357
  • 513
5
votes
2 answers

Return into libc attack

I am trying to implement return-to-libc attack on the below code using format string attack vector. #include #include #include int main(int argc, char *argv[]) { char a[10]; scanf("%s",&a); printf(a); …
re3el
  • 735
  • 2
  • 12
  • 28
5
votes
2 answers

Cannot upgrade libc6, "Already newest version"

I have recently installed Linux Mint on a new machine and I am trying to download virtual box. The problem is it won't download because of this error: Error: Dependency is not satisfiable: libc6 (>=2.27) When I run: sudo apt-get install libc6 It…
Chris Starling
  • 422
  • 6
  • 20
5
votes
3 answers

Does fgetc return EOF on every call after end-of-file reached?

Given the following C code: int eofCount = 0; while (true) { int c = fgetc(stdin); if (c == EOF) eofCount++; } Will eofCount ever become greater than 1? I can't find anything in C docs describing what happens with fgetc after EOF has been…
Alexandre
  • 5,035
  • 7
  • 29
  • 36
5
votes
1 answer

Looking for a pure c-version of math.h functions (no co-processor support)

I have to work with some (semi-)automatical verification software (CBMC (link)) which is statically working on C sources. Floating point is supported, but there are no definitions for all the mathematical functions. The attempt is to check, if it's…
sascha
  • 32,238
  • 6
  • 68
  • 110
5
votes
2 answers

How to compile a program using static library libdl.a

I am trying to compile the example code which is using APIs from libdl library: #include #include #include int main(int argc, char **argv) { void *handle; double (*cosine)(double); char *error; handle…
Rahul Khandelwal
  • 149
  • 1
  • 12
5
votes
2 answers

How does the pstack command work?

I am curious to find how does the pstack command prints the stack trace of all the threads running under the PID? It has to be someway different than the way gdb does since the process runs inside the gdb environment, but pstack is executed after…
g__k
  • 71
  • 1
  • 2
  • 3
5
votes
1 answer

From where in libc source code, is open() getting linked?

I basically need to customize few linux system call interfaces (say sys_open) for my purpose. I am very much aware of GNU Linker ld --wrap=symbol option and use that logic to alter the open() libc wrapper. Although that serves the purpose, I really…
Sandhya Kumar
  • 293
  • 3
  • 11
5
votes
5 answers

How does a program inherit environment variables?

When I use the function getenv() from the Standard C Library, my program inherit the environment variables from its parent. Example: $ export FOO=42 $ <<< 'int main() {printf("%s\n", getenv("FOO"));}' gcc -w -xc - && ./a.exe 42 In libc, the…
nowox
  • 25,978
  • 39
  • 143
  • 293
5
votes
3 answers

GLibc optimizations required

Why is it not possible recompile GLibc turning off all the optimizations (i.e., -O0)? Particularly in doing this: make CFLAGS='-O0 -w' CXXFLAGS='-O0 -w' I get: #error "glibc cannot be compiled without optimization"
badnack
  • 737
  • 1
  • 11
  • 20