Does fprintf use malloc() under the hood?

后端 未结 3 1837
盖世英雄少女心
盖世英雄少女心 2020-12-31 04:06

I want a minimal o-damn-malloc-just-failed handler, which writes some info to a file (probably just standard error). I would prefer to use fprintf() rather than write(), bu

3条回答
  •  春和景丽
    2020-12-31 04:30

    The C standard doesn't guarantee that fprintf won't call malloc under the hood. Indeed, it doesn't guarantee anything about what happens when you override malloc. You should refer to the documentation for your specific C library, or simply write your own fprintf-like function which makes direct syscalls, avoiding any possibility of heap allocation.

提交回复
热议问题