Search code examples
c++clinuxglibcreentrancy

Can glibc sprintf be used in a reentrant function?


Can I use sprintf in a reentrant function if it writes in a local buffer? Something like this:

void reentrant_function () { 
    int i = 4;
    char buffer[20];
    snprintf(buffer, 20, "%d", i); 
}

Solution

  • Sure you can, unless your buffer is static.