Fixed include directory name.
[libsex.git] / libsex / utility.cxx
blob06339356ff66d39cc0818cea8a13d8fe88d62c4d
1 /**
2 * @file
4 * Non-template definitions of formatting-related internal
5 * functions.
6 */
8 #include <libsex/utility.hxx>
9 #include <cassert>
11 bool libsex::vformat(
12 char* const buf,
13 size_t len,
14 const char* const file,
15 unsigned short line,
16 const char* const msg,
17 va_list ap) throw()
19 size_t chars = snprintf(buf, len, "%s:%d: ", file, line);
21 // If buffer was too small, chars contains length
22 // of chars that would've been written. Chars must
23 // be lower than length or else we could not fit
24 // the message into buffer, too.
25 bool didFitIntoBuffer = chars < len;
27 if (didFitIntoBuffer) {
28 size_t newLength = len - chars;
29 char* const newBuffer = buf + chars;
30 chars = vsnprintf(newBuffer, newLength, msg, ap);
31 didFitIntoBuffer = chars <= newLength;
34 return didFitIntoBuffer;
37 bool libsex::format(
38 char* const buf,
39 size_t len,
40 const char* const file,
41 unsigned short line,
42 const char* const msg,
43 ...) throw()
45 va_list ap;
46 va_start(ap, msg);
48 bool result = vformat(buf, len, file, line, msg, ap);
50 va_end(ap);
51 return result;