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
9
votes
2 answers

How to implement redirection of stdout of a child process to a file?

I am implementing I/O redirection in a shell written in Rust. I succeeded in piping between two children processes by using unsafe code with raw file descriptors and pipe() from the libc crate. When I try to redirect stdout of the last child process…
R. Ding
  • 95
  • 1
  • 5
9
votes
1 answer

dlopen in libc and libdl

If a gcc-compiled program is calling dlopen, it has to be compiled with the -ldl option enabled. This means that such a program relies at run time on the library libdl.so. In fact by doing ldd on it we see the line: libdl.so.2 =>…
badnack
  • 737
  • 1
  • 11
  • 20
9
votes
1 answer

How to override standard libc functions?

For example, if I want to override malloc(), what's the best way to do it? Currently the simplest way I know of is: malloc.h #include #define malloc my_malloc void* my_malloc (size_t size); foobar.c #include "malloc.h" void…
theanine
  • 986
  • 3
  • 10
  • 21
9
votes
3 answers

When invoking clock_gettime() may the returned tv_nsec field actually exceed a second?

When you invoke clock_gettime() it returns a timespec structure. struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; I don't find in the man page a garantee that the tv_nsec won't exceed one second. Does the…
yves Baumes
  • 8,836
  • 7
  • 45
  • 74
9
votes
2 answers

Atomically swap contents of two files on Linux

I have two files, A and B, each with its own content. I would like to swap these two files, so A would become B, and B would become A. But I would like to do with a guaranty that no other process will find these two files in an inconsistent state,…
antonone
  • 2,045
  • 1
  • 25
  • 35
9
votes
1 answer

Different offset in libc's backtrace_symbols() and libunwind's unw_get_proc_name()

I make a stack trace at some point in my program. Once with libc's backtrace_symbols() function and once with unw_get_proc_name() from libunwind. backtrace_symbols() output: /home/jj/test/mylib.so(+0x97004)[0x7f6b47ce9004] unw_get_proc_name()…
tur1ng
  • 3,139
  • 5
  • 24
  • 31
9
votes
1 answer

what is libc? what are the functions it includes? how can we get the source code of it?

As per Wikipedia there are many variants of standard C library based on operating system and compilers. Ref: http://en.wikipedia.org/wiki/C_standard_library But I want to understand that how plenty of functions which are declared in different…
Yash
  • 173
  • 2
  • 13
9
votes
6 answers

Unit testing for failed malloc()

What is the best way for unit testing code paths involving a failed malloc()? In most instances, it probably doesn't matter because you're doing something like thingy *my_thingy = malloc(sizeof(thingy)); if (my_thingy == NULL) { fprintf(stderr,…
Pillsy
  • 9,781
  • 1
  • 43
  • 70
8
votes
1 answer

How to build apple's opensource libc?

I'm trying to build apple's opensource libc (from http://www.opensource.apple.com/source/Libc/Libc-763.11/) on my OS X 10.6.8 laptop. This is in an attempt to essentially get a locally generated replica of /usr/lib/libSystem.B.dylib, which I intend…
Vivek
  • 564
  • 4
  • 13
8
votes
2 answers

How can I create a static executable with rustc using glibc instead of musl?

I wrote simple code in C, Go and Rust. foo.c #include int main() { printf("hello\n"); return 0; } foo.go package main import "fmt" func main() { fmt.Println("hello"); } foo.rs fn main() { println!("hello"); } Then I…
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
8
votes
3 answers

What is "namespace cleanliness", and how does glibc achieve it?

I came across this paragraph from this answer by @zwol recently: The __libc_ prefix on read is because there are actually three different names for read in the C library: read, __read, and __libc_read. This is a hack to achieve "namespace…
S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
8
votes
1 answer

Moving to different Linux build system, getting error: undefined symbol: stat

This may just be an issue with the build system I am migrating to, but I'll include differences in the two systems and how I encountered the problem. My old build system is a SLES 10 machine. The gcc/cpp/g++ version is 4.1.0 My new system is on SLES…
Jetson
  • 81
  • 1
  • 3
8
votes
1 answer

Fastest way to generate random numbers

libc has random which uses a nonlinear additive feedback random number generator employing a default table of size 31 long integers to return successive pseudo-random numbers I'm looking for a random function written in Rust with the same speed.…
hansaplast
  • 11,007
  • 2
  • 61
  • 75
8
votes
1 answer

warning: the use of `tmpnam' is dangerous, better use `mkstemp'

(Note: This is not a duplicate question) I'm using the libc function tmpnam, and getting the following warning: warning: the use of 'tmpnam' is dangerous, better use 'mkstemp' My question isn't "how to disable the warning", but rather "what…
Sod Almighty
  • 1,768
  • 1
  • 16
  • 29
8
votes
1 answer

Catching libc error messages, redirecting from /dev/tty

I am trying to catch error messages that libc generates when it detects error conditions. For example, my test code: #include int main() { char* p = (char*)malloc(10); free(p); free(p); } Generates this output $ ./main ***…
Mark Lakata
  • 19,989
  • 5
  • 106
  • 123