2 * Copyright (c) 1997 - 2020 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
35 # pragma warning(disable: 4646)
36 # pragma warning(disable: 4716)
42 static heim_error_code _warnerr(heim_context context, int do_errtext,
43 heim_error_code code, int level, const char *fmt, va_list ap)
44 __attribute__ ((__format__ (__printf__, 5, 0)));
46 static heim_error_code
47 _warnerr(heim_context context, int do_errtext,
48 heim_error_code code, int level, const char *fmt, va_list ap)
51 const char *args[2], **arg;
53 const char *err_str = NULL;
56 args[0] = args[1] = NULL;
59 strlcat(xfmt, "%s", sizeof(xfmt));
61 strlcat(xfmt, ": ", sizeof(xfmt));
62 ret = vasprintf(&msg, fmt, ap);
63 if(ret < 0 || msg == NULL)
67 if (context && do_errtext) {
68 strlcat(xfmt, "%s", sizeof(xfmt));
70 err_str = heim_get_error_message(context, code);
71 if (err_str != NULL) {
74 *arg= "<unknown error>";
78 if (context && heim_get_warn_dest(context))
79 heim_log(context, heim_get_warn_dest(context), level, xfmt, args[0],
82 warnx(xfmt, args[0], args[1]);
84 heim_free_error_message(context, err_str);
88 #define FUNC(ETEXT, CODE, LEVEL) \
89 heim_error_code ret; \
92 ret = _warnerr(context, ETEXT, CODE, LEVEL, fmt, ap); \
96 #define __attribute__(X)
99 * Log a warning to the log, default stderr, include the error from
102 * @param context A Kerberos 5 context.
103 * @param code error code of the last error
104 * @param fmt message to print
105 * @param ap arguments
107 * @ingroup heim_error
111 heim_vwarn(heim_context context, heim_error_code code,
112 const char *fmt, va_list ap)
113 __attribute__ ((__format__ (__printf__, 3, 0)))
115 return _warnerr(context, 1, code, 1, fmt, ap);
119 * Log a warning to the log, default stderr, include the error from
122 * @param context A Kerberos 5 context.
123 * @param code error code of the last error
124 * @param fmt message to print
126 * @ingroup heim_error
130 heim_warn(heim_context context, heim_error_code code, const char *fmt, ...)
131 __attribute__ ((__format__ (__printf__, 3, 4)))
138 * Log a warning to the log, default stderr.
140 * @param context A Kerberos 5 context.
141 * @param fmt message to print
142 * @param ap arguments
144 * @ingroup heim_error
148 heim_vwarnx(heim_context context, const char *fmt, va_list ap)
149 __attribute__ ((__format__ (__printf__, 2, 0)))
151 return _warnerr(context, 0, 0, 1, fmt, ap);
155 * Log a warning to the log, default stderr.
157 * @param context A Kerberos 5 context.
158 * @param fmt message to print
160 * @ingroup heim_error
164 heim_warnx(heim_context context, const char *fmt, ...)
165 __attribute__ ((__format__ (__printf__, 2, 3)))