cf/largefile.m4: Fix build with autoconf-2.72
[heimdal.git] / lib / krb5 / warn.c
blob65a7db6b8ce15c2ddfb7bf36651c379fdfd2fb8f
1 /*
2 * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #if defined(_MSC_VER)
35 # pragma warning(disable: 4646)
36 # pragma warning(disable: 4716)
37 #endif
39 #include "krb5_locl.h"
40 #include <err.h>
42 static krb5_error_code _warnerr(krb5_context context, int do_errtext,
43 krb5_error_code code, int level, const char *fmt, va_list ap)
44 __attribute__ ((__format__ (__printf__, 5, 0)));
46 static krb5_error_code
47 _warnerr(krb5_context context, int do_errtext,
48 krb5_error_code code, int level, const char *fmt, va_list ap)
50 if (do_errtext)
51 return heim_vwarn(context ? context->hcontext : NULL, code, fmt, ap);
52 else
53 return heim_vwarnx(context ? context->hcontext : NULL, fmt, ap);
56 #define FUNC_NORET(ETEXT, CODE, LEVEL) \
57 va_list ap; \
58 va_start(ap, fmt); \
59 (void) _warnerr(context, ETEXT, CODE, LEVEL, fmt, ap); \
60 va_end(ap);
62 #undef __attribute__
63 #define __attribute__(X)
65 /**
66 * Log a warning to the log, default stderr, include the error from
67 * the last failure.
69 * @param context A Kerberos 5 context.
70 * @param code error code of the last error
71 * @param fmt message to print
72 * @param ap arguments
74 * @ingroup krb5_error
77 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
78 krb5_vwarn(krb5_context context, krb5_error_code code,
79 const char *fmt, va_list ap)
80 __attribute__ ((__format__ (__printf__, 3, 0)))
82 return heim_vwarn(context ? context->hcontext : NULL, code, fmt, ap);
85 /**
86 * Log a warning to the log, default stderr, include the error from
87 * the last failure.
89 * @param context A Kerberos 5 context.
90 * @param code error code of the last error
91 * @param fmt message to print
93 * @ingroup krb5_error
96 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
97 krb5_warn(krb5_context context, krb5_error_code code, const char *fmt, ...)
98 __attribute__ ((__format__ (__printf__, 3, 4)))
100 krb5_error_code ret;
101 va_list ap;
103 va_start(ap, fmt);
104 ret = krb5_vwarn(context, code, fmt, ap);
105 va_end(ap);
106 return ret;
110 * Log a warning to the log, default stderr.
112 * @param context A Kerberos 5 context.
113 * @param fmt message to print
114 * @param ap arguments
116 * @ingroup krb5_error
119 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
120 krb5_vwarnx(krb5_context context, const char *fmt, va_list ap)
121 __attribute__ ((__format__ (__printf__, 2, 0)))
123 return heim_vwarnx(context ? context->hcontext : NULL, fmt, ap);
127 * Log a warning to the log, default stderr.
129 * @param context A Kerberos 5 context.
130 * @param fmt message to print
132 * @ingroup krb5_error
135 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
136 krb5_warnx(krb5_context context, const char *fmt, ...)
137 __attribute__ ((__format__ (__printf__, 2, 3)))
139 krb5_error_code ret;
140 va_list ap;
142 va_start(ap, fmt);
143 ret = krb5_vwarnx(context, fmt, ap);
144 va_end(ap);
145 return ret;
149 * Log a warning to the log, default stderr, include bthe error from
150 * the last failure and then exit.
152 * @param context A Kerberos 5 context
153 * @param eval the exit code to exit with
154 * @param code error code of the last error
155 * @param fmt message to print
156 * @param ap arguments
158 * @ingroup krb5_error
161 KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
162 krb5_verr(krb5_context context, int eval, krb5_error_code code,
163 const char *fmt, va_list ap)
164 __attribute__ ((__noreturn__, __format__ (__printf__, 4, 0)))
166 _warnerr(context, 1, code, 0, fmt, ap);
167 exit(eval);
168 UNREACHABLE(return 0);
172 * Log a warning to the log, default stderr, include bthe error from
173 * the last failure and then exit.
175 * @param context A Kerberos 5 context
176 * @param eval the exit code to exit with
177 * @param code error code of the last error
178 * @param fmt message to print
180 * @ingroup krb5_error
183 KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
184 krb5_err(krb5_context context, int eval, krb5_error_code code,
185 const char *fmt, ...)
186 __attribute__ ((__noreturn__, __format__ (__printf__, 4, 5)))
188 FUNC_NORET(1, code, 0);
189 exit(eval);
190 UNREACHABLE(return 0);
194 * Log a warning to the log, default stderr, and then exit.
196 * @param context A Kerberos 5 context
197 * @param eval the exit code to exit with
198 * @param fmt message to print
199 * @param ap arguments
201 * @ingroup krb5_error
204 KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
205 krb5_verrx(krb5_context context, int eval, const char *fmt, va_list ap)
206 __attribute__ ((__noreturn__, __format__ (__printf__, 3, 0)))
208 _warnerr(context, 0, 0, 0, fmt, ap);
209 exit(eval);
210 UNREACHABLE(return 0);
214 * Log a warning to the log, default stderr, and then exit.
216 * @param context A Kerberos 5 context
217 * @param eval the exit code to exit with
218 * @param fmt message to print
220 * @ingroup krb5_error
223 KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
224 krb5_errx(krb5_context context, int eval, const char *fmt, ...)
225 __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)))
227 FUNC_NORET(0, 0, 0);
228 exit(eval);
229 UNREACHABLE(return 0);
233 * Log a warning to the log, default stderr, include bthe error from
234 * the last failure and then abort.
236 * @param context A Kerberos 5 context
237 * @param code error code of the last error
238 * @param fmt message to print
239 * @param ap arguments
241 * @ingroup krb5_error
244 KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
245 krb5_vabort(krb5_context context, krb5_error_code code,
246 const char *fmt, va_list ap)
247 __attribute__ ((__noreturn__, __format__ (__printf__, 3, 0)))
249 _warnerr(context, 1, code, 0, fmt, ap);
250 abort();
251 UNREACHABLE(return 0);
255 * Log a warning to the log, default stderr, include the error from
256 * the last failure and then abort.
258 * @param context A Kerberos 5 context
259 * @param code error code of the last error
260 * @param fmt message to print
261 * @param ... arguments for format string
263 * @ingroup krb5_error
266 KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
267 krb5_abort(krb5_context context, krb5_error_code code, const char *fmt, ...)
268 __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)))
270 FUNC_NORET(1, code, 0);
271 abort();
272 UNREACHABLE(return 0);
275 KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
276 krb5_vabortx(krb5_context context, const char *fmt, va_list ap)
277 __attribute__ ((__noreturn__, __format__ (__printf__, 2, 0)))
279 _warnerr(context, 0, 0, 0, fmt, ap);
280 abort();
281 UNREACHABLE(return 0);
285 * Log a warning to the log, default stderr, and then abort.
287 * @param context A Kerberos 5 context
288 * @param fmt printf format string of message to print
289 * @param ... arguments for format string
291 * @ingroup krb5_error
294 KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
295 krb5_abortx(krb5_context context, const char *fmt, ...)
296 __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3)))
298 FUNC_NORET(0, 0, 0);
299 abort();
300 UNREACHABLE(return 0);
304 * Set the default logging facility.
306 * @param context A Kerberos 5 context
307 * @param fac Facility to use for logging.
309 * @ingroup krb5_error
312 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
313 krb5_set_warn_dest(krb5_context context, krb5_log_facility *fac)
315 return heim_set_warn_dest(context->hcontext, fac);
319 * Get the default logging facility.
321 * @param context A Kerberos 5 context
323 * @ingroup krb5_error
326 KRB5_LIB_FUNCTION krb5_log_facility * KRB5_LIB_CALL
327 krb5_get_warn_dest(krb5_context context)
329 return heim_get_warn_dest(context->hcontext);