Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / perf / ui / util.c
blob1d38ddf01b604a3a81e86b7a12aae27766b1606c
1 // SPDX-License-Identifier: GPL-2.0
2 #include "util.h"
3 #include "../util/debug.h"
4 #include <stdio.h>
6 /*
7 * Default error logging functions
8 */
9 static int perf_stdio__error(const char *format, va_list args)
11 fprintf(stderr, "Error:\n");
12 vfprintf(stderr, format, args);
13 return 0;
16 static int perf_stdio__warning(const char *format, va_list args)
18 if (quiet)
19 return 0;
21 fprintf(stderr, "Warning:\n");
22 vfprintf(stderr, format, args);
23 return 0;
26 static struct perf_error_ops default_eops =
28 .error = perf_stdio__error,
29 .warning = perf_stdio__warning,
32 static struct perf_error_ops *perf_eops = &default_eops;
35 int ui__error(const char *format, ...)
37 int ret;
38 va_list args;
40 va_start(args, format);
41 ret = perf_eops->error(format, args);
42 va_end(args);
44 return ret;
47 int ui__warning(const char *format, ...)
49 int ret;
50 va_list args;
51 if (quiet)
52 return 0;
54 va_start(args, format);
55 ret = perf_eops->warning(format, args);
56 va_end(args);
58 return ret;
61 /**
62 * perf_error__register - Register error logging functions
63 * @eops: The pointer to error logging function struct
65 * Register UI-specific error logging functions. Before calling this,
66 * other logging functions should be unregistered, if any.
68 int perf_error__register(struct perf_error_ops *eops)
70 if (perf_eops != &default_eops)
71 return -1;
73 perf_eops = eops;
74 return 0;
77 /**
78 * perf_error__unregister - Unregister error logging functions
79 * @eops: The pointer to error logging function struct
81 * Unregister already registered error logging functions.
83 int perf_error__unregister(struct perf_error_ops *eops)
85 if (perf_eops != eops)
86 return -1;
88 perf_eops = &default_eops;
89 return 0;