~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_error.c

mergeĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "mysys_priv.h"
17
 
#include <libdrizzle/gettext.h>
18
17
#include "mysys_err.h"
19
 
#include <mystrings/m_string.h>
 
18
#include <m_string.h>
20
19
#include <stdarg.h>
21
 
#include <mystrings/m_ctype.h>
 
20
#include <m_ctype.h>
22
21
 
23
22
/* Define some external variables for error handling */
24
23
 
52
51
  const char            **meh_errmsgs;  /* error messages array */
53
52
  int                   meh_first;      /* error number matching array slot 0 */
54
53
  int                   meh_last;       /* error number matching last slot */
55
 
  bool                  is_globerrs;
56
 
} my_errmsgs_globerrs = {NULL, globerrs, EE_ERROR_FIRST, EE_ERROR_LAST, true};
 
54
} my_errmsgs_globerrs = {NULL, globerrs, EE_ERROR_FIRST, EE_ERROR_LAST};
57
55
 
58
56
static struct my_err_head *my_errmsgs_list= &my_errmsgs_globerrs;
59
57
 
74
72
  struct my_err_head *meh_p;
75
73
  va_list args;
76
74
  char ebuff[ERRMSGSIZE + 20];
 
75
  DBUG_ENTER("my_error");
 
76
  DBUG_PRINT("my", ("nr: %d  MyFlags: %d  errno: %d", nr, MyFlags, errno));
77
77
 
78
78
  /* Search for the error messages array, which could contain the message. */
79
79
  for (meh_p= my_errmsgs_list; meh_p; meh_p= meh_p->meh_next)
82
82
 
83
83
  /* get the error message string. Default, if NULL or empty string (""). */
84
84
  if (! (format= (meh_p && (nr >= meh_p->meh_first)) ?
85
 
         _(meh_p->meh_errmsgs[nr - meh_p->meh_first]) : NULL) || ! *format)
86
 
    (void) snprintf (ebuff, sizeof(ebuff), _("Unknown error %d"), nr);
 
85
         meh_p->meh_errmsgs[nr - meh_p->meh_first] : NULL) || ! *format)
 
86
    (void) snprintf (ebuff, sizeof(ebuff), "Unknown error %d", nr);
87
87
  else
88
88
  {
89
89
    va_start(args,MyFlags);
91
91
    va_end(args);
92
92
  }
93
93
  (*error_handler_hook)(nr, ebuff, MyFlags);
94
 
  return;
 
94
  DBUG_VOID_RETURN;
95
95
}
96
96
 
97
97
 
106
106
      ...       variable list
107
107
*/
108
108
 
109
 
void my_printf_error(uint32_t error, const char *format, myf MyFlags, ...)
 
109
void my_printf_error(uint error, const char *format, myf MyFlags, ...)
110
110
{
111
111
  va_list args;
112
112
  char ebuff[ERRMSGSIZE+20];
 
113
  DBUG_ENTER("my_printf_error");
 
114
  DBUG_PRINT("my", ("nr: %d  MyFlags: %d  errno: %d  Format: %s",
 
115
                    error, MyFlags, errno, format));
113
116
 
114
117
  va_start(args,MyFlags);
115
118
  (void) vsnprintf (ebuff, sizeof(ebuff), format, args);
116
119
  va_end(args);
117
120
  (*error_handler_hook)(error, ebuff, MyFlags);
118
 
  return;
 
121
  DBUG_VOID_RETURN;
119
122
}
120
123
 
121
124
/*
128
131
      MyFlags   Flags
129
132
*/
130
133
 
131
 
void my_message(uint32_t error, const char *str, register myf MyFlags)
 
134
void my_message(uint error, const char *str, register myf MyFlags)
132
135
{
133
136
  (*error_handler_hook)(error, str, MyFlags);
134
137
}
168
171
  meh_p->meh_errmsgs= errmsgs;
169
172
  meh_p->meh_first= first;
170
173
  meh_p->meh_last= last;
171
 
  meh_p->is_globerrs= false;
172
174
 
173
175
  /* Search for the right position in the list. */
174
176
  for (search_meh_pp= &my_errmsgs_list;
182
184
  /* Error numbers must be unique. No overlapping is allowed. */
183
185
  if (*search_meh_pp && ((*search_meh_pp)->meh_first <= last))
184
186
  {
185
 
    free((unsigned char*)meh_p);
 
187
    my_free((uchar*)meh_p, MYF(0));
186
188
    return 1;
187
189
  }
188
190
 
238
240
 
239
241
  /* Save the return value and free the header. */
240
242
  errmsgs= meh_p->meh_errmsgs;
241
 
  bool is_globerrs= meh_p->is_globerrs;
242
 
 
243
 
  free((unsigned char*) meh_p);
244
 
 
245
 
  if (is_globerrs)
246
 
    return NULL;
 
243
  my_free((uchar*) meh_p, MYF(0));
247
244
  
248
245
  return errmsgs;
249
246
}
255
252
  for (list= my_errmsgs_globerrs.meh_next; list; list= next)
256
253
  {
257
254
    next= list->meh_next;
258
 
    free((unsigned char*) list);
 
255
    my_free((uchar*) list, MYF(0));
259
256
  }
260
257
  my_errmsgs_list= &my_errmsgs_globerrs;
261
258
}