Reasonable snprintf-like alternatives to strftime?

Viewed 969

Are there any standard (C, C++, POSIX, Linux...) alternatives to strftime which can be used to

  1. calculate the required size of the string buffer for a given format and time,
  2. truncate the output (instead of leaving the array contents undefined like strftime does) if buffer size is less than required for full output.

For example, snprintf-like semantics for date/time formatting which accept strftime format strings would do perfectly.

Functions like std::put_time in C++11 and later are not an option, because these may attempt to allocate extra memory dynamically and may throw exceptions.

1 Answers
Related