How to write a formatted string to a file using safe action functions?

Currently, I use some non-signal safe functions such as fprintf, snprintfin my signal handlers. But I need to replace it with signaling safe functions like write. But the function writeuses only a buffer or string without formatting. Are there other methods for printing a formatted string?

+4
source share
1 answer

Set the flag in the signal handler. Then make recordings for recording after returning from the signal handler.

static volatile sig_atomic_t sig_rcvd = 0;

void sig_hanlder(int sig)
{
   sig_rcvd = 1;
}

sig_rcvd, , , reset sig_rcvd 0. - , , .

+2

Source: https://habr.com/ru/post/1667341/


All Articles