libc

Fatal signal 7 (SIGBUS) at 0x00000000 (code=2)

隐身守侯 提交于 2019-12-18 04:42:30
问题 While using a OSGi Platform on Android i got this errormsg: Fatal signal 7 (SIGBUS) at 0x595302e0 (code=2) I don't think that my app needs that much space in memory or need a lot of computation power. Its just the OSGi Platform with 20 Bundles. My app is always restarting after that. Any ideas ? 回答1: Even I too found a similar problem and happens to be (code=128) with about fault. Seems to be a data alignment error. To solve this issue, I tried putting a code something like this: *Data = (

Get the time zone GMT offset in C

纵饮孤独 提交于 2019-12-17 16:06:38
问题 I'm using the standard mktime function to turn a struct tm into an epoch time value. The tm fields are populated locally, and I need to get the epoch time as GMT. tm has a gmtoff field to allow you to set the local GMT offset in seconds for just this purpose. But I can't figure out how to get that information. Surely there must be a standard function somewhere that will return the offset? How does localtime do it? 回答1: Just do the following: #define _GNU_SOURCE /* for tm_gmtoff and tm_zone */

How do I reimplement (or wrap) a syscall function on Linux?

▼魔方 西西 提交于 2019-12-17 08:21:23
问题 Suppose I want to completely take over the open() system call, maybe to wrap the actual syscall and perform some logging. One way to do this is to use LD_PRELOAD to load a (user-made) shared object library that takes over the open() entry point. The user-made open() routine then obtains the pointer to the glibc function open() by dlsym() ing it, and calling it. The solution proposed above is a dynamic solution, however. Suppose I want to link my own open() wrapper statically. How would I do

Linking against an old version of libc to provide greater application coverage

痴心易碎 提交于 2019-12-17 02:52:33
问题 Linux binaries are usually dynamically linked to the core system library (libc). This keeps the memory footprint of the binary quite small but binaries which are dependent on the latest libraries will not run on older systems. Conversely, binaries linked to older libraries will run happily on the latest systems. Therefore, in order to ensure our application has good coverage during distribution we need to figure out the oldest libc we can support and link our binary against that. How should

Why printf is not able to handle flags, field width and precisions properly?

老子叫甜甜 提交于 2019-12-13 10:52:23
问题 I'm trying to discover all capabilities of printf and I have tried this : printf("Test:%+*0d", 10, 20); that prints Test:%+100d I have use first the flag + , then the width * and the re-use the flag 0 . Why it's make this output ? I purposely used printf() in a bad way but I wonder why it shows me the number 100? 回答1: This is because, you're supplying syntactical nonsense to the compiler, so it is free to do whatever it wants. Related reading, undefined behavior. Compile your code with

Statically linking system libraries, libc, pthreads, to aid in debugging

走远了吗. 提交于 2019-12-13 06:34:58
问题 I am trying to avoid the situation described in this Stackoverflow entry: Debugging core files generated on a Customer's box. If I compile all the libraries statically will I avoid having to always gather the shared libraries when it core dumps? I essentially want to be in a situation where I can just load up the core file with gdb and examine the crashed application. What should I watch out for if I go down the route of statically linking all the libraries we need. I figure glib and pthreads

How to compile with c11 standard library on OS X with clang?

折月煮酒 提交于 2019-12-13 01:33:17
问题 Hey I am trying to compile c code that uses functions from the c11 standard library on OS X with clang. The compiler option -std=c11 allows me to use c11 language features. But when I am using new functions like at_quick_exit I get the following warning implicit declaration of function 'at_quick_exit' is invalid in C99 . The source code has the following line #include <stdlib.h> The clang option -stdlib does not help. My Systems: OS X Yosemite 10.10.3 $ clang -v Apple LLVM version 6.1.0

Getting IP address, port and connection type from a socket fd

你说的曾经没有我的故事 提交于 2019-12-12 22:06:52
问题 I'm have a tracer process that traces a network application. Given a socket file descriptor belonging to the tracee, would it be possible for the tracer to find the IP it corresponds to(in the case of a server the IP of the interface it binds to, in the case of a client the address of the interface used to make the connection), the port number and the type of connection? Are there libc APIs that could be used to make this work? Any information in /proc that could be used? Also, would there be

-Werror=format: how can the compiler know

若如初见. 提交于 2019-12-12 10:49:37
问题 I wrote this intentionally wrong code printf("%d %d", 1); compiling with g++ and -Werror=format . The compiler gives this very impressive warning: error: format '%d' expects a matching 'int' argument [-Werror=format] As far as I can see, there's no way the compiler can tell that the code is wrong, because the format string isn't parsed until runtime. My question: does the compiler have a special feature that kicks in for printf and similar libc functions, or is this a feature I could use for

Python ctypes calling reboot() from libc on Linux

匆匆过客 提交于 2019-12-12 10:48:46
问题 I'm trying to call the reboot function from libc in Python via ctypes and I just can not get it to work. I've been referencing the man 2 reboot page (http://linux.die.net/man/2/reboot). My kernel version is 2.6.35. Below is the console log from the interactive Python prompt where I'm trying to get my machine to reboot- what am I doing wrong? Why isn't ctypes.get_errno() working? >>> from ctypes import CDLL, get_errno >>> libc = CDLL('libc.so.6') >>> libc.reboot(0xfee1dead, 537993216,