What's the meaning of the %m formatting specifier?

Viewed 25796

The output for this code printed out ‘Success’.

printf("%m\n");
2 Answers

Actually, the manual of printf() concerning %m is quite laconic:

m      (Glibc extension; supported by uClibc and musl.)  Print output
              of strerror(errno).  No argument is required.

But strerror() has a problem in multi-threaded programs: it is not reentrant. The thread-safe version is strerror_r().

A little study of the GLIBC implementation shows that %m is actually equivalent to strerror_r() and not to strerror(). Hence %m is thread-safe! The online manual is consequently wrong (or at least not accurate enough)!

Related