mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Use vsnprintf on unix with a NULL buffer to get required size
This conforms to POSIX.1-2001
This commit is contained in:
parent
957126c11a
commit
7a4ea3e7f5
@ -52,16 +52,7 @@ class OutputDevice : public PdfOutputDevice {
|
||||
#ifdef _MSC_VER
|
||||
return _vscprintf(pszFormat, args);
|
||||
#else
|
||||
char *buf;
|
||||
int res, len=1024;
|
||||
while(true) {
|
||||
buf = new (std::nothrow) char[len+1];
|
||||
if (buf == NULL) { PyErr_NoMemory(); throw pyerr(); }
|
||||
res = vsnprintf(buf, len, pszFormat, args);
|
||||
delete[] buf;
|
||||
if (res >= 0) return res + 1;
|
||||
len *= 2;
|
||||
}
|
||||
return vsnprintf(NULL, 0, pszFormat, args);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user