Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qvsnprintf.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qplatformdefs.h"
5
6#include "qbytearray.h"
7#include "qstring.h"
8
9#include "string.h"
10
12
13#if !defined(QT_VSNPRINTF) || defined(Q_QDOC)
14
37int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
38{
39 if (!str || !fmt)
40 return -1;
41
42 const QByteArray ba = QString::vasprintf(fmt, ap).toLocal8Bit();
43
44 if (n > 0) {
45 size_t blen = qMin(size_t(ba.length()), size_t(n - 1));
46 memcpy(str, ba.constData(), blen);
47 str[blen] = '\0'; // make sure str is always 0 terminated
48 }
49
50 return ba.length();
51}
52
53#else
54
56#include <stdio.h>
58
59int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
60{
61 return QT_VSNPRINTF(str, n, fmt, ap);
62}
63
64#endif
65
82int qsnprintf(char *str, size_t n, const char *fmt, ...)
83{
84 va_list ap;
85 va_start(ap, fmt);
86
87 int ret = qvsnprintf(str, n, fmt, ap);
88 va_end(ap);
89
90 return ret;
91}
92
\inmodule QtCore
Definition qbytearray.h:57
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
qsizetype length() const noexcept
Same as size().
Definition qbytearray.h:499
int qsnprintf(char *str, size_t n, const char *fmt,...)
\target bytearray-qsnprintf
QT_BEGIN_NAMESPACE int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
A portable vsnprintf() function.
static QString vasprintf(const char *format, va_list ap) Q_ATTRIBUTE_FORMAT_PRINTF(1
Definition qstring.cpp:7357
QString str
[2]
Combined button and popup list for selecting options.
Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
return ret
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
GLfloat n
#define QT_BEGIN_INCLUDE_NAMESPACE
#define QT_END_INCLUDE_NAMESPACE
QVideoFrameFormat::PixelFormat fmt
QByteArray ba
[0]