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
6
votes
1 answer

intercepting the openat() system call for GNU tar

I'm trying to intercept the openat() system call on Linux using a custom shared library that I can load via LD_PRELOAD. An example intercept-openat.c has this content: #define _GNU_SOURCE #include #include #include…
Julius Plenz
  • 63
  • 1
  • 3
6
votes
2 answers

How to get Linux file permissions in .NET 5 / .NET 6 without Mono.Posix with p/invoke?

I recently found, that I can make Linux system calls from .NET relatively easy. For example, to see if I need sudo I just make a signature like this: internal class Syscall { [DllImport("libc", SetLastError = true)] internal static extern uint…
Harry
  • 4,524
  • 4
  • 42
  • 81
6
votes
1 answer

What is this implementation of fread in Chromium OS made of?

I was looking at the source code of fread in chromium-os / glibc and became increasingly puzzled about it. NB: I am talking about the source code and NOT the use of fread or other related questions Function prototype as a macro First I was…
Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81
6
votes
2 answers

Can a system call happen in a C program?

Can a system call happen in a C program? Consider this: int main() { int f = open("/tmp/test.txt", O_CREAT | O_RDWR, 0666); write(f, "hello world", 11); close(f); return 0; } In this sample code, open, write, and close are library…
taranom
  • 153
  • 2
  • 12
6
votes
1 answer

How to fix llvmlibc-restrict-system-libc-headers check in Clang Tidy?

I do not understand the llvmlibc-restrict-system-libc-headers check in Clang Tidy (link). I include C libraries in C++ code like this: #include What should I change to fix this Clang Tidy check? Should it be fixed at all?
Wouter Beek
  • 3,307
  • 16
  • 29
6
votes
1 answer

glibc version for aarch64

I'm cross-compiling an application for aarch64 on my x86 Ubuntu Bionic system, and I have problems with glibc version mismatch. My cross-compile toolchain was using v2.27, while the system that is to run the application has v2.24. I thought that it…
MulattoKid
  • 573
  • 6
  • 14
6
votes
4 answers

C++: How to force libc declarations into std::?

So, I find myself in the need of libc in my C++ program. However, I do not like the idea of sprinkling it all over the global namespace. Ideally, I'd like to force the entirety of libc into the std:: namespace so I'd have to do std::memcpy rather…
user438034
6
votes
1 answer

Does gcc links to libc.a or libc.so by default?

I am using gcc 5.4.0 on Ubuntu 16.04 64 bit. When I compile a program: gcc -o prog prog.c GCC automatically links to the C standard library, so I don't have to specifically do that. How can I see which C library does gcc link against to, libc.a…
radiohead
  • 439
  • 4
  • 12
6
votes
2 answers

How do I handle errors from libc functions in an idiomatic Rust manner?

libc's error handling is usually to return something < 0 in case of an error. I find myself doing this over and over: let pid = fork() if pid < 0 { // Please disregard the fact that `Err(pid)` // should be a `&str` or an enum return…
hansaplast
  • 11,007
  • 2
  • 61
  • 75
6
votes
1 answer

bus error when trying to access character on a string in C

I have used this line of code many times (update: when string was a parameter to the function!), however when I try to do it now I get a bus error (both with gcc and clang). I am reproducing the simplest possible code; char *string = "this is a…
theprole
  • 2,274
  • 23
  • 25
6
votes
2 answers

How to do the equivalent of "ulimit -n 400" from within C?

I must run the command "ulimit -n 400" to raise number of allowed open files before I start my program written in C, but is there a way to do the equivalent from within the C program? That is, increase the number of allowed open file descriptors for…
Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
6
votes
4 answers

C printf difference between 0 flag & width attribute and precision flag

I'm currently learning the printf function of libc and I don't understand, what is the difference between: printf("Test : %010d", 10); using the 0 flag and 10 as width specifier and printf("Test : %.10d", 10); using 10 as precision specifier That…
Sadek
  • 175
  • 1
  • 7
6
votes
3 answers

compilation error on clock_gettime and CLOCK_MONOTONIC

I'm using clock_gettime in a program. I've tried including as well as but neither works. I have also added -lrt to my compiler arguments but still I get the same errors. This is on CentOS Linux release 7.2.1511 (Core) gcc (GCC) 4.8.5 20150623 (Red…
Steven
  • 285
  • 1
  • 3
  • 11
6
votes
2 answers

getc() as macro and C standard library function definition, coherent?

In [7.1.4 Use of library functions], I read : Any function declared in a header may be additionally implemented as a function-like macro defined in the header... and Any invocation of a library function that is implemented as a macro shall…
Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
6
votes
2 answers

Why there is no inverse function for gmtime in libc?

In libc there are two functions to convert from system time to calendar time - gmtime and localtime, but only localtime has inverse function - mktime. Why there is no inverse function for gmtime, and if there shouldn't be any, why gmtime exists?
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28