Line | Count | Source |
1 | | // Copyright 2021 Joe Drago. All rights reserved. |
2 | | // SPDX-License-Identifier: BSD-2-Clause |
3 | | |
4 | | #include "avif/internal.h" |
5 | | |
6 | | #include <stdarg.h> |
7 | | #include <stdio.h> |
8 | | #include <string.h> |
9 | | |
10 | | void avifDiagnosticsClearError(avifDiagnostics * diag) |
11 | 63.9k | { |
12 | 63.9k | *diag->error = '\0'; |
13 | 63.9k | } |
14 | | |
15 | | #ifdef __clang__ |
16 | | __attribute__((__format__(__printf__, 2, 3))) |
17 | | #endif |
18 | | void avifDiagnosticsPrintf(avifDiagnostics * diag, const char * format, ...) |
19 | 20.7k | { |
20 | 20.7k | if (!diag) { |
21 | | // It is possible this is NULL (e.g. calls to avifPeekCompatibleFileType()) |
22 | 37 | return; |
23 | 37 | } |
24 | 20.6k | if (*diag->error) { |
25 | | // There is already a detailed error set. |
26 | 9.25k | return; |
27 | 9.25k | } |
28 | | |
29 | 11.4k | va_list args; |
30 | 11.4k | va_start(args, format); |
31 | 11.4k | vsnprintf(diag->error, AVIF_DIAGNOSTICS_ERROR_BUFFER_SIZE, format, args); |
32 | 11.4k | diag->error[AVIF_DIAGNOSTICS_ERROR_BUFFER_SIZE - 1] = '\0'; |
33 | | va_end(args); |
34 | 11.4k | } |