Menu
  • HOME
  • TAGS

How to find out if offset cursor is at EOF with lseek()?

c,eof,libc,lseek

lseek returns the (new) position. If it's acceptable that the file position is at the end after the test, the following works: off_t old_position = lseek(fd, 0, SEEK_CUR); off_t end_position = lseek(fd, 0, SEEK_END); if(old_position == end_position) { /* cursor already has been at the end */ } Now, the...

killall(1) equivalent system call or C library call

linux,system,libc,kill-process

As far as I know there is no general way to do it, as there is no general way to get the pid by its process name. You have to collect the pids of related processes and call the int kill(pid_t pid, int signo); function At least you can try...

Is this possible with printf?

c,printf,libc

Yes, you can just combine it to this: printf("%5.5s\n", string); So if your string is 1, the output is: 1 //^ 4 Spaces here And if your string is 123456, the output is: 12345 //^ 6 doesn't get displayed Also for more information about printf() and as a reference see...

nasm: jump when input is NULL

c,assembly,nasm,libc

Your first instruction is the problem: cmp rdi, 0. You're comparing the string pointer, passed to my_puts, to the value 0 to determine if you should print "(null)" rather than comparing the first byte of the string to 0. I'm supposing if you pass a 0 pointer, that would be...

How can I measure elapsed time when encrypting using openssl in linux by C

linux,posix,libc

The easiest way for you to do this is by using the clock() function from <time.h> to report the amount of CPU time used by the calling process. From SUSv4: The clock() function shall return the implementation's best approximation to the processor time used by the process since the beginning...

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

c,linux,glibc,libc

According to opengroup The tv_nsec member is only valid if greater than or equal to zero, and less than the number of nanoseconds in a second (1000 million). The time interval described by this structure is (tv_sec * 10'-.4m'9'.4m' + tv_nsec) nanoseconds. So according to opengroup, it looks official that...

ELF loading on MIPS, malloc issue

mips,elf,libc,musl

It's been a while since I tried to do MIPS stuff, but I think your aux vector needs to look like this: // main()'s pseudo arguments. #define AT_PAGESZ 6 argv: .word name .word 0 // End of argv. .word 0 // End of envp. // Auxv .word AT_PAGESZ .word 4096...

uclinux - link with libc.so.0 library

linux,embedded-linux,libc,uclibc,uclinux

Seems like the toolchain you are using is built for glibc. But the target board has uClibc installed. These two libraries are incompatible. At runtime they are incompatible, and at compile-time they are incompatible. You cannot "tell the compiler to use a different & incompatible library. You need to obtain...

multi-byte characters in libc regcomp and regexec

regex,utf-8,glibc,libc,multibyte-functions

Can you use a regex to build your regex? Here's a javascript example, (though I know you aren't using js): function Examp () { var uString = "猫机+猫+猫ymg+sah猫"; var plussed = uString.replace(/(.)(?=[\+\*])/ig,"($1)"); console.log("Starting with string: " + uString + "\r\n" + "Result: " + plussed); uString = "猫机+猫*猫ymg+s\\a+I+h猫"; plussed =...

Tell which version of symbols are available for linking against (in libc)?

linux,gcc,linker,glibc,libc

It seems to me that you have mixed up your libraries and binaries a bit... /lib/libc.so.6 on most Linux distributions is a 32-bit shared object and should contain the *@GLIBC_2.0 symbols. If you are on an x86_64 platform, though, I would expect GCC to produce an 64-bit binary by default....

Problems with a local installation of libc

python,glibc,libc,theano

So, what I did instead was to install a local version of libc and to change LD_LIBRARY_PATH in my .bashrc file to point to it See this answer for why that can't work. Why my setting of LD_LIBRARY_PATH didn't force my new (local) libc to use the new (local)...

Atomically swap contents of two files on Linux

linux,libc

You can use the (fairly recent) linux syscall renameat2 Here is the definition : int renameat2(int olddir, const char *oldname, int newdir, const char *newname, unsigned int flags); You can find its source code here if needed : https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/namei.c#n4203 It's basically the same as renameat, but if you pass the...

Load both musl libc.so and gcc libc.so in the same process?

glibc,elf,libc,musl

Is it possible to have both GNU and musl libc.so in the same process? It's possible to load them both, yes. But the result will promptly crash, so it's a useless thing to do. but I want my shared object use musl's libc.so But why? In any case, you'll...

ioctl prototype in solaris libc

oracle,solaris,libc,ioctl

Your ioctl on /devices/pseudo/[email protected]:poll device (or /dev/pool) seems to be handled by kernel function from common/io/devpoll.c file (online copy - http://fxr.watson.org/fxr/source/common/io/devpoll.c?v=OPENSOLARIS) More exact, by the dpioctl function: 692 dpioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, int *rvalp) zhihuifan, after checking your stacktrace I see that you program...

Why the 3rd parameter of __libc_start_main has name ubp_av and not argv?

c,libc

libc is a library which is deeply tied to the specific OS, processor, and often compiler used. So, it's not uncommon to see some fairly arcane stuff in the libc sources. In this case, ubp_av is an unbounded pointer to argv. GCC provides the (not-well-documented) __bounded and __unbounded type annotations...

How to uninitialize the entropy of /dev/urandom in C?

c,random,syscall,libc

As /dev/random and urandom are vital for security functions, allowing to tamper them would contradict their purpose. But you can add your own driver, or just replace calls to them with dummies (or use named pipes from a dummy for testing) instead. Note: do not replace the driver on a...

memccpy return lower memory address than the src starting address

c,libc

That's probably the problem of the 64bit pointer and 32bit pointer. Your ft_memccpy would return a 64 bit pointer, so it outputs 0x7fff712edc44 While the system memccpy returned a 32bit's 0x712edc44 ...

What does “f” stand for in C standard library function names?

c,naming,libc

Your question in general is too general but I can explain a few examples. fgets, fopen, fclose, … — The ”f“ stands for “file”. These functions accept or return a FILE * pointer as opposed to a file number as the POSIX functions do. printf, scanf, … — The ”f“...

ualarm() equivalent (Android Bionic libc)

android,linux,android-ndk,libc,bionic

OK, create_timer was the key. Too bad nobody answered with an example in time. I've built this code by simplifying this answer. #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <signal.h> #include <time.h> // Handler that will be called every its.it_value.tv_sec seconds + its.it_value.tv_nsec nanoseconds until you kill the timer static...

Where is FreeBSD libc's _write defined?

freebsd,system-calls,libc

Keep in mind that _write is a /very/ complicated syscall. Since it functions on a file handle which may be file on any type of filesystem or even a network socket, it basically forks off to places all over the kernel. The wiki page you link to is the right...

What is the difference between setpgrp and tcsetpgrp

c,linux,unix,libc,tty

tcsetprgrp is a function that is used for set the process group based on the file descriptor which is connected to terminal. If the file descriptor not connected to the terminal that time it will give the error. setpgrp is used for making the calling process as a process group...

version `GLIBC_2.11' not found while using gcc

linux,gcc,g++,glibc,libc

I copied gcc folder to the new machine. That's your problem: don't copy, install appropriate GCC package instead. Most UNIX systems, including Linux, guarantee backward compatibility: a binary compiled on an older system continues to run on a newer one. The reverse is not true: a binary compiled on...

Set a breakpoint into LibC with gdb

linker,gdb,debug-symbols,libc

I don't know how you came up with the symbol name that you are using, but here's what I see on my system (Ubuntu 14.04.1): $ objdump --dynamic-syms /lib/x86_64-linux-gnu/libc.so.6 |grep vfprintf 0000000000049cf0 g DF .text 00000000000051a8 GLIBC_2.2.5 _IO_vfprintf 00000000001097e0 g DF .text 0000000000000111 GLIBC_2.3.4 __vfprintf_chk 0000000000049cf0 g DF .text 00000000000051a8...