author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /rsync/trace.h | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
-rw-r--r-- | rsync/trace.h | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/rsync/trace.h b/rsync/trace.h new file mode 100644 index 0000000..60a6477 --- a/dev/null +++ b/rsync/trace.h | |||
@@ -0,0 +1,122 @@ | |||
1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- | ||
2 | * | ||
3 | * librsync -- generate and apply network deltas | ||
4 | * $Id$ | ||
5 | * | ||
6 | * Copyright (C) 2000, 2001 by Martin Pool <mbp@samba.org> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU Lesser General Public License as published by | ||
10 | * the Free Software Foundation; either version 2.1 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | */ | ||
22 | |||
23 | |||
24 | /* | ||
25 | * TODO: A function like perror that includes strerror output. Apache | ||
26 | * does this by adding flags as well as the severity level which say | ||
27 | * whether such information should be included. | ||
28 | */ | ||
29 | |||
30 | |||
31 | /* | ||
32 | * trace may be turned off. | ||
33 | * | ||
34 | * error is always on, but you can return and continue in some way | ||
35 | * | ||
36 | * fatal terminates the whole process | ||
37 | */ | ||
38 | |||
39 | void rs_fatal0(char const *s, ...); | ||
40 | void rs_error0(char const *s, ...); | ||
41 | void rs_trace0(char const *s, ...); | ||
42 | |||
43 | void rs_log0_nofn(int level, char const *fmt, ...); | ||
44 | |||
45 | #ifdef __GNUC__ | ||
46 | |||
47 | void rs_log0(int level, char const *fn, char const *fmt, ...) | ||
48 | __attribute__ ((format(printf, 3, 4))); | ||
49 | |||
50 | #ifdef DO_RS_TRACE | ||
51 | # define rs_trace(fmt, arg...) \ | ||
52 | do { rs_log0(RS_LOG_DEBUG, __FUNCTION__, fmt , ##arg); \ | ||
53 | } while (0) | ||
54 | #else | ||
55 | # define rs_trace(s, str...) | ||
56 | #endif/* !DO_RS_TRACE */ | ||
57 | |||
58 | /* | ||
59 | * TODO: Don't assume this is a gcc thing; rather test in autoconf for | ||
60 | * support for __FUNCTION__ and varargs macros. One simple way might | ||
61 | * just be to try compiling the definition of one of these functions! | ||
62 | * | ||
63 | * TODO: Also look for the C9X predefined identifier `_function', or | ||
64 | * whatever it's called. | ||
65 | */ | ||
66 | |||
67 | #define rs_log(l, s, str...) do { \ | ||
68 | rs_log0((l), __FUNCTION__, (s) , ##str); \ | ||
69 | } while (0) | ||
70 | |||
71 | |||
72 | #define rs_error(s, str...) do { \ | ||
73 | rs_log0(RS_LOG_ERR, __FUNCTION__, (s) , ##str); \ | ||
74 | } while (0) | ||
75 | |||
76 | |||
77 | #define rs_fatal(s, str...) do { \ | ||
78 | rs_log0(RS_LOG_CRIT, __FUNCTION__, \ | ||
79 | (s) , ##str); \ | ||
80 | abort(); \ | ||
81 | } while (0) | ||
82 | |||
83 | |||
84 | #else /************************* ! __GNUC__ */ | ||
85 | |||
86 | # define rs_fatal rs_fatal0 | ||
87 | # define rs_error rs_error0 | ||
88 | # define rs_log rs_log0_nofn | ||
89 | |||
90 | # ifdef DO_RS_TRACE | ||
91 | # define rs_trace rs_trace0 | ||
92 | # endif /* DO_RS_TRACE */ | ||
93 | #endif /* ! __GNUC__ */ | ||
94 | |||
95 | |||
96 | void rs_log0(int level, char const *fn, char const *fmt, ...); | ||
97 | |||
98 | |||
99 | enum { | ||
100 | RS_LOG_PRIMASK = 7, /**< Mask to extract priority | ||
101 | part. \internal */ | ||
102 | |||
103 | RS_LOG_NONAME = 8 /**< \b Don't show function name in | ||
104 | message. */ | ||
105 | }; | ||
106 | |||
107 | |||
108 | |||
109 | /** | ||
110 | * \macro rs_trace_enabled() | ||
111 | * | ||
112 | * Call this before putting too much effort into generating trace | ||
113 | * messages. | ||
114 | */ | ||
115 | |||
116 | extern int rs_trace_level; | ||
117 | |||
118 | #ifdef DO_RS_TRACE | ||
119 | # define rs_trace_enabled() ((rs_trace_level & RS_LOG_PRIMASK) >= RS_LOG_DEBUG) | ||
120 | #else | ||
121 | # define rs_trace_enabled() 0 | ||
122 | #endif | ||