src/lib: Use standard std::vsnprintf() instead of hacking our own

This commit is contained in:
Povilas Kanapickas 2021-11-01 02:52:36 +02:00
parent b793675ef8
commit ef08470286
8 changed files with 2 additions and 89 deletions

View File

@ -91,7 +91,6 @@ if (UNIX)
check_function_exists (poll HAVE_POLL) check_function_exists (poll HAVE_POLL)
check_function_exists (sigwait HAVE_POSIX_SIGWAIT) check_function_exists (sigwait HAVE_POSIX_SIGWAIT)
check_function_exists (strftime HAVE_STRFTIME) check_function_exists (strftime HAVE_STRFTIME)
check_function_exists (vsnprintf HAVE_VSNPRINTF)
check_function_exists (inet_aton HAVE_INET_ATON) check_function_exists (inet_aton HAVE_INET_ATON)
# For some reason, the check_function_exists macro doesn't detect # For some reason, the check_function_exists macro doesn't detect

View File

@ -94,9 +94,6 @@
/* Define to 1 if you have the <unistd.h> header file. */ /* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H} #cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H}
/* Define to 1 if you have the `vsnprintf` function. */
#cmakedefine HAVE_VSNPRINTF ${HAVE_VSNPRINTF}
/* Define to 1 if you have the <wchar.h> header file. */ /* Define to 1 if you have the <wchar.h> header file. */
#cmakedefine HAVE_WCHAR_H ${HAVE_WCHAR_H} #cmakedefine HAVE_WCHAR_H ${HAVE_WCHAR_H}

View File

@ -46,16 +46,6 @@ public:
//! @name manipulators //! @name manipulators
//@{ //@{
//! printf() to limited size buffer with va_list
/*!
This method is equivalent to vsprintf() except it will not write
more than \c n bytes to the buffer, returning -1 if the output
was truncated and the number of bytes written not including the
trailing NUL otherwise.
*/
virtual int vsnprintf(char* str,
int size, const char* fmt, va_list ap);
//! Convert multibyte string to wide character string //! Convert multibyte string to wide character string
virtual int convStringMBToWC(wchar_t*, virtual int convStringMBToWC(wchar_t*,
const char*, UInt32 n, bool* errors); const char*, UInt32 n, bool* errors);

View File

@ -25,7 +25,6 @@
// //
#include "arch/multibyte.h" #include "arch/multibyte.h"
#include "arch/vsnprintf.h"
ArchStringUnix::ArchStringUnix() ArchStringUnix::ArchStringUnix()
{ {

View File

@ -1,67 +0,0 @@
/*
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "arch/IArchString.h"
#if HAVE_VSNPRINTF
#if !defined(ARCH_VSNPRINTF)
# define ARCH_VSNPRINTF vsnprintf
#endif
int
IArchString::vsnprintf(char* str, int size, const char* fmt, va_list ap)
{
int n = ::ARCH_VSNPRINTF(str, size, fmt, ap);
if (n > size) {
n = -1;
}
return n;
}
#elif SYSAPI_UNIX // !HAVE_VSNPRINTF
#include <stdio.h>
int
IArchString::vsnprintf(char* str, int size, const char* fmt, va_list ap)
{
static FILE* bitbucket = fopen("/dev/null", "w");
if (bitbucket == NULL) {
// uh oh
if (size > 0) {
str[0] = '\0';
}
return 0;
}
else {
// count the characters using the bitbucket
int n = vfprintf(bitbucket, fmt, ap);
if (n + 1 <= size) {
// it'll fit so print it into str
vsprintf(str, fmt, ap);
}
return n;
}
}
#else // !HAVE_VSNPRINTF && !SYSAPI_UNIX
#error vsnprintf not implemented
#endif // !HAVE_VSNPRINTF

View File

@ -26,11 +26,6 @@
// ArchStringWindows // ArchStringWindows
// //
#include "arch/multibyte.h"
#define HAVE_VSNPRINTF 1
#define ARCH_VSNPRINTF _vsnprintf
#include "arch/vsnprintf.h"
ArchStringWindows::ArchStringWindows() ArchStringWindows::ArchStringWindows()
{ {
} }

View File

@ -145,7 +145,7 @@ Log::print(const char* file, int line, const char* fmt, ...)
// try printing into the buffer // try printing into the buffer
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
int n = ARCH->vsnprintf(buffer, len - sPad, fmt, args); int n = std::vsnprintf(buffer, len - sPad, fmt, args);
va_end(args); va_end(args);
// if the buffer wasn't big enough then make it bigger and try again // if the buffer wasn't big enough then make it bigger and try again

View File

@ -171,7 +171,7 @@ sprintf(const char* fmt, ...)
// try printing into the buffer // try printing into the buffer
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
int n = ARCH->vsnprintf(buffer, len, fmt, args); int n = std::vsnprintf(buffer, len, fmt, args);
va_end(args); va_end(args);
// if the buffer wasn't big enough then make it bigger and try again // if the buffer wasn't big enough then make it bigger and try again