title: Why does C not have an snwprintf function?
body: <p>Does anyone know why there is no <code>snwprintf</code> function in the C standard library?</p>
  
  <p>I am aware of <code>swprintf</code>, but that doesn't have the same semantics of a true, <code>wchar_t</code> version of <code>snprintf</code>.  As far as I can tell, there is no easy way to implement an <code>snwprintf</code> function using <code>[v]swprintf</code>:</p>
  
  <p>Unlike <code>snprintf</code>, <code>swprintf</code> does not return the necessary buffer size; if the supplied buffer is insufficient, it simply returns -1.  This is indistinguishable from failure due to encoding errors, so I can't keep retrying with progressively larger buffers hoping that it eventually will succeed.</p>
  
  <p>I suppose I could set the last element of the buffer to be non-NUL, call <code>swprintf</code>, and assume that truncation occurred if that element is NUL afterward.  However, is that guaranteed to work?  The standard does not specify what state the buffer should be in if <code>swprintf</code> fails. (In contrast, <code>snprintf</code> describes which characters are written and which are discarded.)</p>