libc

Is snprintf() ALWAYS null terminating?

我与影子孤独终老i 提交于 2019-11-26 10:48:54
问题 Is snprintf always null terminating the destination buffer? In other words, is this sufficient: char dst[10]; snprintf(dst, sizeof (dst), \"blah %s\", somestr); or do you have to do like this, if somestr is long enough? char dst[10]; somestr[sizeof (dst) - 1] = \'\\0\'; snprintf(dst, sizeof (dst) - 1, \"blah %s\", somestr); I am interested both in what the standard says and what some popular libc might do which is not standard behavior. 回答1: As the other answers establish: It should: snprintf

Compiling without libc

≡放荡痞女 提交于 2019-11-26 08:47:59
问题 I want to compile my C-code without the (g)libc. How can I deactivate it and which functions depend on it? I tried -nostdlib but it doesn\'t help: The code is compilable and runs, but I can still find the name of the libc in the hexdump of my executable. 回答1: If you compile your code with -nostdlib , you won't be able to call any C library functions (of course), but you also don't get the regular C bootstrap code. In particular, the real entry point of a program on Linux is not main() , but

How to use debug version of libc

梦想的初衷 提交于 2019-11-26 05:24:38
问题 Short version of question: How can I get gdb to use the debugging symbols for libc? Longer version: I am debugging a program with gdb and I want to see information about a futex used by libc. However, at some point during debugging I get output such as: Catchpoint 2 (call to syscall futex), 0x00007ffff772b73e in ?? () from /lib/libc.so.6 (gdb) bt #0 0x00007ffff772b73e in ?? () from /lib/libc.so.6 #1 0x00007ffff767fb90 in ?? () from /lib/libc.so.6 #2 0x00007ffff767a4c0 in vfprintf () from /lib

Is malloc/free a syscall or a library routine provided by libc?

浪子不回头ぞ 提交于 2019-11-26 03:59:41
问题 If malloc/free is implemented as a library routine in libc, then is it implemented on top of the sbrk syscall or the mmap syscall, or something else? And to be general, does the function declared in sys/syscall.h contains ALL the system calls in the target machine? 回答1: malloc and free are standard C library functions which are to be implemented by each C implementation. The C standard only defines the way in which these functions behave and the behavior expected from them. How they are to be

How can I link to a specific glibc version?

三世轮回 提交于 2019-11-26 03:24:28
问题 When I compile something on my Ubuntu Lucid 10.04 PC it gets linked against glibc. Lucid uses 2.11 of glibc. When I run this binary on another PC with an older glibc, the command fails saying there\'s no glibc 2.11... As far as I know glibc uses symbol versioning. Can I force gcc to link against a specific symbol version? In my concrete use I try to compile a gcc cross toolchain for ARM. 回答1: You are correct in that glibc uses symbol versioning. If you are curious, the symbol versioning