16 #include "mysys_priv.h"
17 #include "mysys_err.h"
22 #include "my_handler_errors.h"
25 #define ERRMSGSIZE (512)
51 static struct my_err_head
53 struct my_err_head *meh_next;
54 const char** (*get_errmsgs) ();
57 } my_errmsgs_globerrs = {NULL, get_global_errmsgs, EE_ERROR_FIRST, EE_ERROR_LAST};
59 static struct my_err_head *my_errmsgs_list= &my_errmsgs_globerrs;
72 char *my_strerror(
char *
buf,
size_t len,
int nr)
82 if ((nr >= HA_ERR_FIRST) && (nr <= HA_ERR_LAST))
83 msg= (
char *) handler_error_messages[nr - HA_ERR_FIRST];
86 strmake(buf, msg, len - 1);
96 strerror_s(buf, len, nr);
97 #elif ((defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE >= 200112L)) || \
98 (defined _XOPEN_SOURCE && (_XOPEN_SOURCE >= 600))) && \
100 strerror_r(nr, buf, len);
101 #elif defined _GNU_SOURCE
102 char *r= strerror_r(nr, buf, len);
104 strmake(buf, r, len - 1);
106 strerror_r(nr, buf, len);
115 strmake(buf,
"unknown error", len - 1);
133 const char *my_get_err_msg(
int nr)
136 struct my_err_head *meh_p;
139 for (meh_p= my_errmsgs_list; meh_p; meh_p= meh_p->meh_next)
140 if (nr <= meh_p->meh_last)
148 if (!(format= (meh_p && (nr >= meh_p->meh_first)) ?
149 meh_p->get_errmsgs()[nr - meh_p->meh_first] : NULL) ||
168 void my_error(
int nr, myf MyFlags, ...)
172 char ebuff[ERRMSGSIZE];
173 DBUG_ENTER(
"my_error");
174 DBUG_PRINT(
"my", (
"nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno));
176 if (!(format = my_get_err_msg(nr)))
177 (void) my_snprintf(ebuff,
sizeof(ebuff),
"Unknown error %d", nr);
180 va_start(args,MyFlags);
181 (void) my_vsnprintf_ex(&my_charset_utf8_general_ci, ebuff,
182 sizeof(ebuff), format, args);
185 (*error_handler_hook)(nr, ebuff, MyFlags);
202 void my_printf_error(uint error,
const char *format, myf MyFlags, ...)
205 char ebuff[ERRMSGSIZE];
206 DBUG_ENTER(
"my_printf_error");
207 DBUG_PRINT(
"my", (
"nr: %d MyFlags: %d errno: %d Format: %s",
208 error, MyFlags, errno, format));
210 va_start(args,MyFlags);
211 (void) my_vsnprintf_ex(&my_charset_utf8_general_ci, ebuff,
212 sizeof(ebuff), format, args);
214 (*error_handler_hook)(error, ebuff, MyFlags);
230 void my_printv_error(uint error,
const char *format, myf MyFlags, va_list ap)
232 char ebuff[ERRMSGSIZE];
233 DBUG_ENTER(
"my_printv_error");
234 DBUG_PRINT(
"my", (
"nr: %d MyFlags: %d errno: %d format: %s",
235 error, MyFlags, errno, format));
237 (void) my_vsnprintf(ebuff,
sizeof(ebuff), format, ap);
238 (*error_handler_hook)(error, ebuff, MyFlags);
250 void(*sql_print_warning_hook)(
const char *format,...);
251 void my_printf_warning(
const char *format, ...)
254 char wbuff[ERRMSGSIZE];
255 DBUG_ENTER(
"my_printf_warning");
256 DBUG_PRINT(
"my", (
"Format: %s", format));
257 va_start(args,format);
258 (void) my_vsnprintf (wbuff,
sizeof(wbuff), format, args);
260 (*sql_print_warning_hook)(wbuff);
275 void my_message(uint error,
const char *str,
register myf MyFlags)
277 (*error_handler_hook)(error, str, MyFlags);
301 int my_error_register(
const char** (*get_errmsgs) (),
int first,
int last)
303 struct my_err_head *meh_p;
304 struct my_err_head **search_meh_pp;
307 if (! (meh_p= (
struct my_err_head*) my_malloc(
sizeof(
struct my_err_head),
310 meh_p->get_errmsgs= get_errmsgs;
311 meh_p->meh_first= first;
312 meh_p->meh_last= last;
315 for (search_meh_pp= &my_errmsgs_list;
317 search_meh_pp= &(*search_meh_pp)->meh_next)
319 if ((*search_meh_pp)->meh_last > first)
324 if (*search_meh_pp && ((*search_meh_pp)->meh_first <= last))
331 meh_p->meh_next= *search_meh_pp;
332 *search_meh_pp= meh_p;
357 const char **my_error_unregister(
int first,
int last)
359 struct my_err_head *meh_p;
360 struct my_err_head **search_meh_pp;
361 const char **errmsgs;
364 for (search_meh_pp= &my_errmsgs_list;
366 search_meh_pp= &(*search_meh_pp)->meh_next)
368 if (((*search_meh_pp)->meh_first == first) &&
369 ((*search_meh_pp)->meh_last == last))
372 if (! *search_meh_pp)
376 meh_p= *search_meh_pp;
377 *search_meh_pp= meh_p->meh_next;
380 errmsgs= meh_p->get_errmsgs();
398 void my_error_unregister_all(
void)
400 struct my_err_head *
cursor, *saved_next;
402 for (cursor= my_errmsgs_globerrs.meh_next; cursor != NULL; cursor= saved_next)
405 saved_next= cursor->meh_next;
409 my_errmsgs_globerrs.meh_next= NULL;
411 my_errmsgs_list= &my_errmsgs_globerrs;