1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | #include "Debug.hpp" |
16 | |
17 | #include <string> |
18 | #include <stdarg.h> |
19 | |
20 | namespace rr |
21 | { |
22 | |
23 | void tracev(const char *format, va_list args) |
24 | { |
25 | #ifndef RR_DISABLE_TRACE |
26 | if(false) |
27 | { |
28 | FILE *file = fopen(TRACE_OUTPUT_FILE, "a" ); |
29 | |
30 | if(file) |
31 | { |
32 | vfprintf(file, format, args); |
33 | fclose(file); |
34 | } |
35 | } |
36 | #endif |
37 | } |
38 | |
39 | void trace(const char *format, ...) |
40 | { |
41 | va_list vararg; |
42 | va_start(vararg, format); |
43 | tracev(format, vararg); |
44 | va_end(vararg); |
45 | } |
46 | |
47 | void warn(const char *format, ...) |
48 | { |
49 | va_list vararg; |
50 | va_start(vararg, format); |
51 | tracev(format, vararg); |
52 | va_end(vararg); |
53 | |
54 | va_start(vararg, format); |
55 | vfprintf(stderr, format, vararg); |
56 | va_end(vararg); |
57 | } |
58 | |
59 | void abort(const char *format, ...) |
60 | { |
61 | va_list vararg; |
62 | |
63 | va_start(vararg, format); |
64 | tracev(format, vararg); |
65 | va_end(vararg); |
66 | |
67 | va_start(vararg, format); |
68 | vfprintf(stderr, format, vararg); |
69 | va_end(vararg); |
70 | |
71 | ::abort(); |
72 | } |
73 | |
74 | } // namespace rr |
75 | |