6

I'm converting C++ code from Windows to work under Linux and I came across this function "vsprintf_s". It is a Microsoft specific function so I would like to ask if there is a replacement in Linux? Thanks

Khalid Ismail
  • 63
  • 1
  • 5
  • 3
    See [Do you use the TR 24731 'safe' functions?](https://stackoverflow.com/questions/372980/do-you-use-the-tr-24731-safe-functions) for information about the `*_s()` functions not being directly available via non-Microsoft libraries — eg not available on Linux or Mac OS X. No, it isn't directly available. You can get pretty close with `vsnprintf()`, but there are definitely differences in the calling sequences (multiple differences). – Jonathan Leffler Feb 18 '16 at 17:17
  • 1
    See [this](http://stackoverflow.com/questions/4785381/replacement-for-ms-vscprintf-on-macos-linux). – Martin Feb 18 '16 at 17:18
  • @Martin the link solve the issue for _vscprintf function which is different than vsprintf_s – Khalid Ismail Feb 19 '16 at 11:47

1 Answers1

5

Looks like vsnprintf() would be a suitable replacement according to linux.die.net.

Dakota Sides
  • 101
  • 2
  • 4
    It's close, but the overflow-handling behaviours are quite different. `vsprintf_s` aborts the program on attempted overflow. `vsnprintf` truncates the output and carries on. – user4581301 Feb 18 '16 at 17:43