0001
0002 #include "util.h"
0003 #include "../util/debug.h"
0004 #include <stdio.h>
0005
0006
0007
0008
0009 static int perf_stdio__error(const char *format, va_list args)
0010 {
0011 fprintf(stderr, "Error:\n");
0012 vfprintf(stderr, format, args);
0013 return 0;
0014 }
0015
0016 static int perf_stdio__warning(const char *format, va_list args)
0017 {
0018 fprintf(stderr, "Warning:\n");
0019 vfprintf(stderr, format, args);
0020 return 0;
0021 }
0022
0023 static struct perf_error_ops default_eops =
0024 {
0025 .error = perf_stdio__error,
0026 .warning = perf_stdio__warning,
0027 };
0028
0029 static struct perf_error_ops *perf_eops = &default_eops;
0030
0031
0032 int ui__error(const char *format, ...)
0033 {
0034 int ret;
0035 va_list args;
0036
0037 va_start(args, format);
0038 ret = perf_eops->error(format, args);
0039 va_end(args);
0040
0041 return ret;
0042 }
0043
0044 int ui__warning(const char *format, ...)
0045 {
0046 int ret;
0047 va_list args;
0048
0049 va_start(args, format);
0050 ret = perf_eops->warning(format, args);
0051 va_end(args);
0052
0053 return ret;
0054 }
0055
0056
0057
0058
0059
0060
0061
0062
0063 int perf_error__register(struct perf_error_ops *eops)
0064 {
0065 if (perf_eops != &default_eops)
0066 return -1;
0067
0068 perf_eops = eops;
0069 return 0;
0070 }
0071
0072
0073
0074
0075
0076
0077
0078 int perf_error__unregister(struct perf_error_ops *eops)
0079 {
0080 if (perf_eops != eops)
0081 return -1;
0082
0083 perf_eops = &default_eops;
0084 return 0;
0085 }