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

后端 未结 2 1470
梦谈多话
梦谈多话 2020-12-09 01:23

The output for this code printed out ‘Success’.

printf(\"%m\\n\");
2条回答
  •  囚心锁ツ
    2020-12-09 01:51

    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(). Hence %m is thread-safe!

提交回复
热议问题