From 277d809ba4f8c60812286f15a116d2520e2eb0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 28 Feb 2023 15:12:46 +0100 Subject: [PATCH] DNS Lookup: Use ideomatic cstdio include Task-number: QTBUG-108873 Pick-to: 6.5 Change-Id: I646f0c985adc45a17103b5f98394f3def4b6ada2 Reviewed-by: Marc Mutz Reviewed-by: Konrad Kujawa Reviewed-by: Timur Pocheptsov --- examples/network/dnslookup/dnslookup.cpp | 40 +++++++++++++----------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/network/dnslookup/dnslookup.cpp b/examples/network/dnslookup/dnslookup.cpp index d54a68a4fd..bfcd60813b 100644 --- a/examples/network/dnslookup/dnslookup.cpp +++ b/examples/network/dnslookup/dnslookup.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include using namespace Qt::StringLiterals; @@ -123,13 +123,13 @@ void DnsManager::execute() void DnsManager::showResults() { if (dns->error() != QDnsLookup::NoError) - printf("Error: %i (%s)\n", dns->error(), qPrintable(dns->errorString())); + std::printf("Error: %i (%s)\n", dns->error(), qPrintable(dns->errorString())); // CNAME records const QList cnameRecords = dns->canonicalNameRecords(); for (const QDnsDomainNameRecord &record : cnameRecords) { - printf("%s\t%i\tIN\tCNAME\t%s\n", qPrintable(record.name()), record.timeToLive(), - qPrintable(record.value())); + std::printf("%s\t%i\tIN\tCNAME\t%s\n", qPrintable(record.name()), record.timeToLive(), + qPrintable(record.value())); } // A and AAAA records @@ -137,36 +137,37 @@ void DnsManager::showResults() for (const QDnsHostAddressRecord &record : aRecords) { const char *type = (record.value().protocol() == QAbstractSocket::IPv6Protocol) ? "AAAA" : "A"; - printf("%s\t%i\tIN\t%s\t%s\n", qPrintable(record.name()), record.timeToLive(), type, - qPrintable(record.value().toString())); + std::printf("%s\t%i\tIN\t%s\t%s\n", qPrintable(record.name()), record.timeToLive(), type, + qPrintable(record.value().toString())); } // MX records const QList mxRecords = dns->mailExchangeRecords(); for (const QDnsMailExchangeRecord &record : mxRecords) { - printf("%s\t%i\tIN\tMX\t%u %s\n", qPrintable(record.name()), record.timeToLive(), - record.preference(), qPrintable(record.exchange())); + std::printf("%s\t%i\tIN\tMX\t%u %s\n", qPrintable(record.name()), record.timeToLive(), + record.preference(), qPrintable(record.exchange())); } // NS records const QList nsRecords = dns->nameServerRecords(); for (const QDnsDomainNameRecord &record : nsRecords) { - printf("%s\t%i\tIN\tNS\t%s\n", qPrintable(record.name()), record.timeToLive(), - qPrintable(record.value())); + std::printf("%s\t%i\tIN\tNS\t%s\n", qPrintable(record.name()), record.timeToLive(), + qPrintable(record.value())); } // PTR records const QList ptrRecords = dns->pointerRecords(); for (const QDnsDomainNameRecord &record : ptrRecords) { - printf("%s\t%i\tIN\tPTR\t%s\n", qPrintable(record.name()), record.timeToLive(), - qPrintable(record.value())); + std::printf("%s\t%i\tIN\tPTR\t%s\n", qPrintable(record.name()), record.timeToLive(), + qPrintable(record.value())); } // SRV records const QList srvRecords = dns->serviceRecords(); for (const QDnsServiceRecord &record : srvRecords) { - printf("%s\t%i\tIN\tSRV\t%u %u %u %s\n", qPrintable(record.name()), record.timeToLive(), - record.priority(), record.weight(), record.port(), qPrintable(record.target())); + std::printf("%s\t%i\tIN\tSRV\t%u %u %u %s\n", qPrintable(record.name()), + record.timeToLive(), record.priority(), record.weight(), record.port(), + qPrintable(record.target())); } // TXT records @@ -176,8 +177,8 @@ void DnsManager::showResults() const QList dnsRecords = record.values(); for (const QByteArray &ba : dnsRecords) values << "\"" + QString::fromLatin1(ba) + "\""; - printf("%s\t%i\tIN\tTXT\t%s\n", qPrintable(record.name()), record.timeToLive(), - qPrintable(values.join(' '))); + std::printf("%s\t%i\tIN\tTXT\t%s\n", qPrintable(record.name()), record.timeToLive(), + qPrintable(values.join(' '))); } QCoreApplication::instance()->quit(); @@ -202,9 +203,10 @@ int main(int argc, char *argv[]) case Status::Ok: break; case Status::Error: - fputs(qPrintable(parseResult.errorString.value_or(u"Unknown error occurred"_qs)), stderr); - fputs("\n\n", stderr); - fputs(qPrintable(parser.helpText()), stderr); + std::fputs(qPrintable(parseResult.errorString.value_or(u"Unknown error occurred"_qs)), + stderr); + std::fputs("\n\n", stderr); + std::fputs(qPrintable(parser.helpText()), stderr); return 1; case Status::VersionRequested: parser.showVersion();