~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_error.c

  • Committer: Brian Aker
  • Date: 2008-07-28 18:01:38 UTC
  • Revision ID: brian@tangent.org-20080728180138-q2pxlq0qiapvqsdn
Remove YEAR field type

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "config.h"
17
 
 
18
 
#include <cstdio>
 
16
#include "mysys_priv.h"
 
17
#include "mysys_err.h"
 
18
#include <m_string.h>
19
19
#include <stdarg.h>
20
 
 
21
 
#include <drizzled/gettext.h>
22
 
#include "drizzled/my_error.h"
23
 
#include "drizzled/definitions.h"
24
 
 
25
 
/* Error message numbers in global map */
26
 
const char * globerrs[GLOBERRS];
27
 
 
28
 
error_handler_func error_handler_hook= NULL;
29
 
 
30
 
 
31
 
void init_glob_errs()
32
 
{
33
 
  EE(EE_CANTCREATEFILE) = N_("Can't create/write to file '%s' (Errcode: %d)");
34
 
  EE(EE_READ)           = N_("Error reading file '%s' (Errcode: %d)");
35
 
  EE(EE_WRITE)          = N_("Error writing file '%s' (Errcode: %d)");
36
 
  EE(EE_BADCLOSE)       = N_("Error on close of '%s' (Errcode: %d)");
37
 
  EE(EE_OUTOFMEMORY)    = N_("Out of memory (Needed %u bytes)");
38
 
  EE(EE_DELETE)         = N_("Error on delete of '%s' (Errcode: %d)");
39
 
  EE(EE_LINK)           = N_("Error on rename of '%s' to '%s' (Errcode: %d)");
40
 
  EE(EE_EOFERR)         = N_("Unexpected eof found when reading file '%s' (Errcode: %d)");
41
 
  EE(EE_CANTLOCK)       = N_("Can't lock file (Errcode: %d)");
42
 
  EE(EE_CANTUNLOCK)     = N_("Can't unlock file (Errcode: %d)");
43
 
  EE(EE_DIR)            = N_("Can't read dir of '%s' (Errcode: %d)");
44
 
  EE(EE_STAT)           = N_("Can't get stat of '%s' (Errcode: %d)");
45
 
  EE(EE_CANT_CHSIZE)    = N_("Can't change size of file (Errcode: %d)");
46
 
  EE(EE_CANT_OPEN_STREAM)= N_("Can't open stream from handle (Errcode: %d)");
47
 
  EE(EE_GETWD)          = N_("Can't get working dirctory (Errcode: %d)");
48
 
  EE(EE_SETWD)          = N_("Can't change dir to '%s' (Errcode: %d)");
49
 
  EE(EE_LINK_WARNING)   = N_("Warning: '%s' had %d links");
50
 
  EE(EE_OPEN_WARNING)   = N_("Warning: %d files and %d streams is left open\n");
51
 
  EE(EE_DISK_FULL)      = N_("Disk is full writing '%s'. Waiting for someone to free space...");
52
 
  EE(EE_CANT_MKDIR)     = N_("Can't create directory '%s' (Errcode: %d)");
53
 
  EE(EE_UNKNOWN_CHARSET)= N_("Character set '%s' is not a compiled character set and is not specified in the %s file");
54
 
  EE(EE_OUT_OF_FILERESOURCES)= N_("Out of resources when opening file '%s' (Errcode: %d)");
55
 
  EE(EE_CANT_READLINK)= N_("Can't read value for symlink '%s' (Error %d)");
56
 
  EE(EE_CANT_SYMLINK)= N_("Can't create symlink '%s' pointing at '%s' (Error %d)");
57
 
  EE(EE_REALPATH)= N_("Error on realpath() on '%s' (Error %d)");
58
 
  EE(EE_SYNC)=   N_("Can't sync file '%s' to disk (Errcode: %d)");
59
 
  EE(EE_UNKNOWN_COLLATION)= N_("Collation '%s' is not a compiled collation and is not specified in the %s file");
60
 
  EE(EE_FILENOTFOUND)   = N_("File '%s' not found (Errcode: %d)");
61
 
  EE(EE_FILE_NOT_CLOSED) = N_("File '%s' (fileno: %d) was not closed");
62
 
}
 
20
#include <m_ctype.h>
 
21
 
 
22
/* Define some external variables for error handling */
63
23
 
64
24
/*
65
25
  WARNING!
70
30
  my_printf_error(ER_CODE, format, MYF(N), ...)
71
31
*/
72
32
 
 
33
char errbuff[NRERRBUFFS][ERRMSGSIZE];
 
34
 
73
35
/*
74
36
  Message texts are registered into a linked list of 'my_err_head' structs.
75
37
  Each struct contains (1.) an array of pointers to C character strings with
89
51
  const char            **meh_errmsgs;  /* error messages array */
90
52
  int                   meh_first;      /* error number matching array slot 0 */
91
53
  int                   meh_last;       /* error number matching last slot */
92
 
  bool                  is_globerrs;
93
 
} my_errmsgs_globerrs = {NULL, globerrs, EE_ERROR_FIRST, EE_ERROR_LAST, true};
 
54
} my_errmsgs_globerrs = {NULL, globerrs, EE_ERROR_FIRST, EE_ERROR_LAST};
94
55
 
95
56
static struct my_err_head *my_errmsgs_list= &my_errmsgs_globerrs;
96
57
 
119
80
 
120
81
  /* get the error message string. Default, if NULL or empty string (""). */
121
82
  if (! (format= (meh_p && (nr >= meh_p->meh_first)) ?
122
 
         _(meh_p->meh_errmsgs[nr - meh_p->meh_first]) : NULL) || ! *format)
123
 
    (void) snprintf (ebuff, sizeof(ebuff), _("Unknown error %d"), nr);
 
83
         meh_p->meh_errmsgs[nr - meh_p->meh_first] : NULL) || ! *format)
 
84
    (void) snprintf (ebuff, sizeof(ebuff), "Unknown error %d", nr);
124
85
  else
125
86
  {
126
87
    va_start(args,MyFlags);
143
104
      ...       variable list
144
105
*/
145
106
 
146
 
void my_printf_error(uint32_t error, const char *format, myf MyFlags, ...)
 
107
void my_printf_error(uint error, const char *format, myf MyFlags, ...)
147
108
{
148
109
  va_list args;
149
110
  char ebuff[ERRMSGSIZE+20];
165
126
      MyFlags   Flags
166
127
*/
167
128
 
168
 
void my_message(uint32_t error, const char *str, register myf MyFlags)
 
129
void my_message(uint error, const char *str, register myf MyFlags)
169
130
{
170
131
  (*error_handler_hook)(error, str, MyFlags);
171
132
}
199
160
  struct my_err_head **search_meh_pp;
200
161
 
201
162
  /* Allocate a new header structure. */
202
 
  if (! (meh_p= (struct my_err_head*) malloc(sizeof(struct my_err_head))))
 
163
  if (! (meh_p= (struct my_err_head*) my_malloc(sizeof(struct my_err_head),
 
164
                                                MYF(MY_WME))))
203
165
    return 1;
204
166
  meh_p->meh_errmsgs= errmsgs;
205
167
  meh_p->meh_first= first;
206
168
  meh_p->meh_last= last;
207
 
  meh_p->is_globerrs= false;
208
169
 
209
170
  /* Search for the right position in the list. */
210
171
  for (search_meh_pp= &my_errmsgs_list;
218
179
  /* Error numbers must be unique. No overlapping is allowed. */
219
180
  if (*search_meh_pp && ((*search_meh_pp)->meh_first <= last))
220
181
  {
221
 
    free((unsigned char*)meh_p);
 
182
    my_free((uchar*)meh_p, MYF(0));
222
183
    return 1;
223
184
  }
224
185
 
274
235
 
275
236
  /* Save the return value and free the header. */
276
237
  errmsgs= meh_p->meh_errmsgs;
277
 
  bool is_globerrs= meh_p->is_globerrs;
278
 
 
279
 
  free((unsigned char*) meh_p);
280
 
 
281
 
  if (is_globerrs)
282
 
    return NULL;
283
 
 
 
238
  my_free((uchar*) meh_p, MYF(0));
 
239
  
284
240
  return errmsgs;
285
241
}
286
242
 
291
247
  for (list= my_errmsgs_globerrs.meh_next; list; list= next)
292
248
  {
293
249
    next= list->meh_next;
294
 
    free((unsigned char*) list);
 
250
    my_free((uchar*) list, MYF(0));
295
251
  }
296
252
  my_errmsgs_list= &my_errmsgs_globerrs;
297
253
}