~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_error.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

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>
17
18
#include "mysys_err.h"
18
 
#include <m_string.h>
 
19
#include <mystrings/m_string.h>
19
20
#include <stdarg.h>
20
 
#include <m_ctype.h>
 
21
#include <mystrings/m_ctype.h>
21
22
 
22
23
/* Define some external variables for error handling */
23
24
 
51
52
  const char            **meh_errmsgs;  /* error messages array */
52
53
  int                   meh_first;      /* error number matching array slot 0 */
53
54
  int                   meh_last;       /* error number matching last slot */
54
 
} my_errmsgs_globerrs = {NULL, globerrs, EE_ERROR_FIRST, EE_ERROR_LAST};
 
55
  bool                  is_globerrs;
 
56
} my_errmsgs_globerrs = {NULL, globerrs, EE_ERROR_FIRST, EE_ERROR_LAST, true};
55
57
 
56
58
static struct my_err_head *my_errmsgs_list= &my_errmsgs_globerrs;
57
59
 
72
74
  struct my_err_head *meh_p;
73
75
  va_list args;
74
76
  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
 
  DBUG_VOID_RETURN;
 
94
  return;
95
95
}
96
96
 
97
97
 
106
106
      ...       variable list
107
107
*/
108
108
 
109
 
void my_printf_error(uint error, const char *format, myf MyFlags, ...)
 
109
void my_printf_error(uint32_t 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));
116
113
 
117
114
  va_start(args,MyFlags);
118
115
  (void) vsnprintf (ebuff, sizeof(ebuff), format, args);
119
116
  va_end(args);
120
117
  (*error_handler_hook)(error, ebuff, MyFlags);
121
 
  DBUG_VOID_RETURN;
 
118
  return;
122
119
}
123
120
 
124
121
/*
131
128
      MyFlags   Flags
132
129
*/
133
130
 
134
 
void my_message(uint error, const char *str, register myf MyFlags)
 
131
void my_message(uint32_t error, const char *str, register myf MyFlags)
135
132
{
136
133
  (*error_handler_hook)(error, str, MyFlags);
137
134
}
171
168
  meh_p->meh_errmsgs= errmsgs;
172
169
  meh_p->meh_first= first;
173
170
  meh_p->meh_last= last;
 
171
  meh_p->is_globerrs= false;
174
172
 
175
173
  /* Search for the right position in the list. */
176
174
  for (search_meh_pp= &my_errmsgs_list;
184
182
  /* Error numbers must be unique. No overlapping is allowed. */
185
183
  if (*search_meh_pp && ((*search_meh_pp)->meh_first <= last))
186
184
  {
187
 
    my_free((uchar*)meh_p, MYF(0));
 
185
    free((unsigned char*)meh_p);
188
186
    return 1;
189
187
  }
190
188
 
240
238
 
241
239
  /* Save the return value and free the header. */
242
240
  errmsgs= meh_p->meh_errmsgs;
243
 
  my_free((uchar*) meh_p, MYF(0));
 
241
  bool is_globerrs= meh_p->is_globerrs;
 
242
 
 
243
  free((unsigned char*) meh_p);
 
244
 
 
245
  if (is_globerrs)
 
246
    return NULL;
244
247
  
245
248
  return errmsgs;
246
249
}
252
255
  for (list= my_errmsgs_globerrs.meh_next; list; list= next)
253
256
  {
254
257
    next= list->meh_next;
255
 
    my_free((uchar*) list, MYF(0));
 
258
    free((unsigned char*) list);
256
259
  }
257
260
  my_errmsgs_list= &my_errmsgs_globerrs;
258
261
}