1#include "util.h"
2#include "../debug.h"
3
4
5
6
7
8static int perf_stdio__error(const char *format, va_list args)
9{
10 fprintf(stderr, "Error:\n");
11 vfprintf(stderr, format, args);
12 return 0;
13}
14
15static int perf_stdio__warning(const char *format, va_list args)
16{
17 fprintf(stderr, "Warning:\n");
18 vfprintf(stderr, format, args);
19 return 0;
20}
21
22static struct perf_error_ops default_eops =
23{
24 .error = perf_stdio__error,
25 .warning = perf_stdio__warning,
26};
27
28static struct perf_error_ops *perf_eops = &default_eops;
29
30
31int ui__error(const char *format, ...)
32{
33 int ret;
34 va_list args;
35
36 va_start(args, format);
37 ret = perf_eops->error(format, args);
38 va_end(args);
39
40 return ret;
41}
42
43int ui__warning(const char *format, ...)
44{
45 int ret;
46 va_list args;
47
48 va_start(args, format);
49 ret = perf_eops->warning(format, args);
50 va_end(args);
51
52 return ret;
53}
54
55
56
57
58
59
60
61
62
63int perf_error__register(struct perf_error_ops *eops)
64{
65 if (perf_eops != &default_eops)
66 return -1;
67
68 perf_eops = eops;
69 return 0;
70}
71
72
73
74
75
76
77
78int perf_error__unregister(struct perf_error_ops *eops)
79{
80 if (perf_eops != eops)
81 return -1;
82
83 perf_eops = &default_eops;
84 return 0;
85}
86