File: stringutils.cc

package info (click to toggle)
xosview 1.25-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,136 kB
  • sloc: cpp: 11,982; makefile: 154; ansic: 32; awk: 13; sh: 8
file content (23 lines) | stat: -rw-r--r-- 666 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "stringutils.h"

#include <iostream>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

void snprintf_or_abort(char* str, size_t size, const char* format, ...) {
    va_list args;
    va_start(args, format);
    int needed = vsnprintf(str, size, format, args);
    va_end(args);
    if (needed < 0) {
        std::cerr << "Internal error: vsnprintf returned an error in "
                "snprintf_or_abort" << std::endl;
        abort();
    }
    if ((size_t)needed >= size) {
      std::cerr << "Internal error: Buffer to snprintf_or_abort too small, "
          "required " << needed << " but got " << size << std::endl;
      abort();
    }
}