libc

Determing the number of bytes ready to be recv()'d

↘锁芯ラ 提交于 2019-11-27 06:31:06
问题 I can use select() to determine if a call to recv() would block, but once I've determined that their are bytes to be read, is their a way to query how many bytes are currently available before I actually call recv()? 回答1: If your OS provides it (and most do), you can use ioctl(..,FIONREAD,..): int get_n_readable_bytes(int fd) { int n = -1; if (ioctl(fd, FIONREAD, &n) < 0) { perror("ioctl failed"); return -1; } return n; } Windows provides an analogous ioctlsocket(..,FIONREAD,..), which

Replacing extrordinarily slow pow() function

妖精的绣舞 提交于 2019-11-27 01:48:45
问题 We have a CFD solver and while running a simulation, it was found to run extraordinarily slow on some machines but not others. Using Intel VTune, it was found the following line was the problem (in Fortran): RHOV= RHO_INF*((1.0_wp - COEFF*EXP(F0)))**(1.0_wp/(GAMM - 1.0_wp)) Drilling in with VTune, the problem was traced to the call pow assembly line and when tracing the stack, it showed it was using __slowpow() . After some searching, this page showed up complaining about the same thing. On

Why the absolute value of the max negative integer -2147483648 is still -2147483648?

柔情痞子 提交于 2019-11-27 01:48:35
问题 The result of abs(-2147483648) is -2147483648, isn't it? it seems unacceptable. printf("abs(-2147483648): %d\n", abs(-2147483648)); output: abs(-2147483648): -2147483648 回答1: The standard says about abs() : The abs , labs , and llabs functions compute the absolute value of an integer j . If the result cannot be represented, the behavior is undefined. And the result indeed cannot be represented because the 2's complement representation of signed integers isn't symmetric. Think about it... If

Compiling without libc

南楼画角 提交于 2019-11-26 23:49: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. ataylor 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 rather a function called _start() . The standard libraries normally provide a version of this that

Getting GCC to compile without inserting call to memcpy

蓝咒 提交于 2019-11-26 21:34:41
问题 I'm currently using GCC 4.5.3, compiled for PowerPC 440, and am compiling some code that doesn't require libc. I don't have any direct calls to memcpy(), but the compiler seems to be inserting one during the build. There are linker options like -nostdlib, -nostartfiles, -nodefaultlibs but I'm unable to use them as I'm not doing the linking phase. I'm only compiling. With something like this: $ powerpc-440-eabi-gcc -O2 -g -c -o output.o input.c If I check the output.o with nm, I see a

How to use debug version of libc

你。 提交于 2019-11-26 18:38:43
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/libc.so.6 #3 0x00007ffff768565a in printf () from /lib/libc.so.6 .... When I run info sharedlibrary in

Linux function to get mount points

不问归期 提交于 2019-11-26 18:22:12
问题 Is there a function (or interface; ioctl, netlink etc) in the standard Linux libs that will return the current mounts directly from the kernel without parsing /proc? strace ing the mount command, it looks like it parses files in /proc 回答1: Please see the clarification at the bottom of the answer for the reasoning being used in this answer. Is there any reason that you would not use the getmntent libc library call? I do realize that it's not the same as an 'all in one' system call, but it

How to link to a different libc file?

☆樱花仙子☆ 提交于 2019-11-26 17:03:18
问题 I want to supply the shared libraries along with my program rather than using the target system's due to version differences. ldd says my program uses these shared libs: linux-gate.so.1 => (0xf7ef0000)**(made by kernel)** libc.so.6 => /lib32/libc.so.6 (0xf7d88000)**(libc-2.7.so)** /lib/ld-linux.so.2 (0xf7ef1000)**(ld-2.7.so)** I have successfully linked ld-xxx.so by compiling with: gcc -std=c99 -D_POSIX_C_SOURCE=200112L -O2 -m32 -s -Wl,-dynamic-linker,ld-2.7.so myprogram.c But I have not

I need a list of Async-Signal-Safe Functions from glibc

隐身守侯 提交于 2019-11-26 16:37:35
问题 Non syscall's wrappers but something like snprintf(), dprintf() 回答1: I am pretty sure you have to see the documentation Edit : How about this list then? From man signal : NOTES The effects of this call in a multi-threaded process are unspecified. The routine handler must be very careful, since processing elsewhere was interrupted at some arbitrary point. POSIX has the concept of "safe function". If a signal interrupts an unsafe function, and handler calls an unsafe function, then the behavior

What is the rationale for fread/fwrite taking size and count as arguments?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 12:23:37
问题 We had a discussion here at work regarding why fread and fwrite take a size per member and count and return the number of members read/written rather than just taking a buffer and size. The only use for it we could come up with is if you want to read/write an array of structs which aren\'t evenly divisible by the platform alignment and hence have been padded but that can\'t be so common as to warrant this choice in design. From FREAD(3) : The function fread() reads nmemb elements of data,