summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <[email protected]>2023-06-01 13:47:52 +0300
committerQt Cherry-pick Bot <[email protected]>2023-08-01 08:15:03 +0000
commit4f5b6967bb92f01af6d6c9821c2f35fbada22b84 (patch)
tree8072bfb6cc57fe4b04b81f312536fa9f6f2ba7cb
parent687415e10cd7de8018410407ad0e25cf691c0d7f (diff)
CTF: Use wfopen in windows
Change-Id: If54fe2b0af32a097cac6f485900ec5e353d92dd9 Reviewed-by: Hatem ElKharashy <[email protected]> Reviewed-by: Janne Koskinen <[email protected]> (cherry picked from commit cc3f18e5e91c3c378ade45ec4c13d756bb9b5ae9) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r--src/plugins/tracing/qctflib.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/plugins/tracing/qctflib.cpp b/src/plugins/tracing/qctflib.cpp
index 367ee3c3c8e..ec1b22f2120 100644
--- a/src/plugins/tracing/qctflib.cpp
+++ b/src/plugins/tracing/qctflib.cpp
@@ -38,6 +38,15 @@ static QByteArray &operator<<(QByteArray &arr, T val)
return arr;
}
+static FILE *openFile(const QString &filename, const QString &mode)
+{
+#ifdef Q_OS_WINDOWS
+ return _wfopen(qUtf16Printable(filename), qUtf16Printable(mode));
+#else
+ return fopen(qPrintable(filename), qPrintable(mode));
+#endif
+}
+
QCtfLibImpl *QCtfLibImpl::s_instance = nullptr;
QCtfLib *QCtfLibImpl::instance()
@@ -68,7 +77,7 @@ QCtfLibImpl::QCtfLibImpl()
}
const QString filename = location + QStringLiteral("/session.json");
- FILE *file = fopen(qPrintable(filename), "rb");
+ FILE *file = openFile(qPrintable(filename), "rb"_L1);
if (!file) {
qCWarning(lcDebugTrace) << "unable to open session file: "
<< filename << ", " << qt_error_string();
@@ -134,7 +143,7 @@ QCtfLibImpl::QCtfLibImpl()
void QCtfLibImpl::writeMetadata(const QString &metadata, bool overwrite)
{
FILE *file = nullptr;
- file = fopen(qPrintable(m_location + "/metadata"_L1), overwrite ? "w+b": "ab");
+ file = openFile(qPrintable(m_location + "/metadata"_L1), overwrite ? "w+b"_L1: "ab"_L1);
if (!file)
return;
@@ -150,7 +159,7 @@ void QCtfLibImpl::writeMetadata(const QString &metadata, bool overwrite)
void QCtfLibImpl::writeCtfPacket(QCtfLibImpl::Channel &ch)
{
FILE *file = nullptr;
- file = fopen(ch.channelName, "ab");
+ file = openFile(ch.channelName, "ab"_L1);
if (file) {
/* Each packet contains header and context, which are defined in the metadata.txt */
QByteArray packet;
@@ -273,7 +282,7 @@ void QCtfLibImpl::doTracepoint(const QCtfTracePointEvent &point, const QByteArra
m_threadIndices.insert(thread, m_threadIndices.size());
sprintf(ch.channelName, "%s/channel_%d", qPrintable(m_location), m_threadIndices[thread]);
FILE *f = nullptr;
- f = fopen(ch.channelName, "wb");
+ f = openFile(ch.channelName, "wb"_L1);
if (f)
fclose(f);
ch.minTimestamp = ch.maxTimestamp = timestamp;