File indexing completed on 2024-12-22 04:15:57

0001 /*
0002  * This file is part of Krita
0003  *
0004  * SPDX-FileCopyrightText: 2022 L. E. Segovia <amy@amyspark.me>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #ifndef KIS_TIFF_LOGGER_H
0010 #define KIS_TIFF_LOGGER_H
0011 
0012 #include <QString>
0013 
0014 #include <cstdio>
0015 
0016 #include <kis_debug.h>
0017 
0018 QString formatVarArgs(const char *fmt, va_list args)
0019 {
0020     int size = 4096;
0021     QByteArray buf(size, 0);
0022 #ifdef _WIN32
0023     int n = vsnprintf_s(buf.data(), size, size - 1, fmt, args);
0024 #else
0025     int n = vsnprintf(buf.data(), size, fmt, args);
0026 #endif
0027     while (n >= size || buf.at(size - 2)) {
0028         size *= 2;
0029         buf.resize(size);
0030         buf[size - 1] = 0;
0031         buf[size - 2] = 0;
0032 #ifdef _WIN32
0033         n = vsnprintf_s(buf.data(), size, size - 1, fmt, args);
0034 #else
0035         n = vsnprintf(buf.data(), size, fmt, args);
0036 #endif
0037     }
0038 
0039     if (n) {
0040         return {buf};
0041     } else {
0042         return {};
0043     }
0044 }
0045 
0046 void KisTiffErrorHandler(const char *module, const char *fmt, va_list args)
0047 {
0048     QString msg("%1: %2");
0049 
0050     errFile << msg.arg(module, formatVarArgs(fmt, args));
0051 }
0052 
0053 void KisTiffWarningHandler(const char *module, const char *fmt, va_list args)
0054 {
0055     QString msg("%1: %2");
0056 
0057     warnFile << msg.arg(module, formatVarArgs(fmt, args));
0058 }
0059 
0060 #endif