The world's most popular open source database
#include <my_global.h>#include <my_sys.h>#include <m_string.h>#include <errno.h>#include <my_getopt.h>#include <help_start.h>#include <help_end.h>Include dependency graph for perror.c:

Go to the source code of this file.
Classes | |
| struct | ha_errors |
Defines | |
| #define | PERROR_VERSION "2.10" |
Typedefs | |
| typedef ha_errors | HA_ERRORS |
Functions | |
| static void | print_version (void) |
| static void | usage (void) |
| static my_bool | get_one_option (int optid, const struct my_option *opt __attribute__((unused)), char *argument __attribute__((unused))) |
| static int | get_options (int *argc, char ***argv) |
| static const char * | get_ha_error_msg (int code) |
| int | main (int argc, char *argv[]) |
Variables | |
| static my_bool | verbose |
| static my_bool | print_all_codes |
| static struct my_option | my_long_options [] |
| static HA_ERRORS | ha_errlist [] |
| #define PERROR_VERSION "2.10" |
| static const char* get_ha_error_msg | ( | int | code | ) | [static] |
Definition at line 178 of file perror.c.
References ha_errors::errcode, ha_errlist, ha_errors::msg, and NullS.
Referenced by main().
00179 { 00180 HA_ERRORS *ha_err_ptr; 00181 00182 for (ha_err_ptr=ha_errlist ; ha_err_ptr->errcode ;ha_err_ptr++) 00183 if (ha_err_ptr->errcode == code) 00184 return ha_err_ptr->msg; 00185 return NullS; 00186 }
Here is the caller graph for this function:

| static my_bool get_one_option | ( | int | optid, | |
| const struct my_option *opt | __attribute__((unused)), | |||
| char *argument | __attribute__((unused)) | |||
| ) | [static] |
Definition at line 141 of file perror.c.
References exit, print_version(), usage(), and verbose.
00143 { 00144 switch (optid) { 00145 case 's': 00146 verbose=0; 00147 break; 00148 case 'V': 00149 print_version(); 00150 exit(0); 00151 break; 00152 case 'I': 00153 case '?': 00154 usage(); 00155 exit(0); 00156 break; 00157 } 00158 return 0; 00159 }
Here is the call graph for this function:

| static int get_options | ( | int * | argc, | |
| char *** | argv | |||
| ) | [static] |
Definition at line 162 of file perror.c.
References exit, get_one_option(), handle_options(), my_long_options, print_all_codes, and usage().
00163 { 00164 int ho_error; 00165 00166 if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) 00167 exit(ho_error); 00168 00169 if (!*argc && !print_all_codes) 00170 { 00171 usage(); 00172 return 1; 00173 } 00174 return 0; 00175 } /* get_options */
Here is the call graph for this function:

| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Definition at line 189 of file perror.c.
References atoi(), ha_errors::errcode, error, exit, free, get_ha_error_msg(), get_options(), ha_errlist, malloc, ha_errors::msg, my_charset_latin1, MY_INIT, my_strnncoll, ndb_error_string(), ndbd_exit_string(), NULL, print_all_codes, strcmp(), strlen(), strmov(), and verbose.
00190 { 00191 int error,code,found; 00192 const char *msg; 00193 char *unknown_error = 0; 00194 MY_INIT(argv[0]); 00195 00196 if (get_options(&argc,&argv)) 00197 exit(1); 00198 00199 error=0; 00200 #ifdef HAVE_SYS_ERRLIST 00201 if (print_all_codes) 00202 { 00203 HA_ERRORS *ha_err_ptr; 00204 for (code=1 ; code < sys_nerr ; code++) 00205 { 00206 if (sys_errlist[code][0]) 00207 { /* Skip if no error-text */ 00208 printf("%3d = %s\n",code,sys_errlist[code]); 00209 } 00210 } 00211 for (ha_err_ptr=ha_errlist ; ha_err_ptr->errcode ;ha_err_ptr++) 00212 printf("%3d = %s\n",ha_err_ptr->errcode,ha_err_ptr->msg); 00213 } 00214 else 00215 #endif 00216 { 00217 /* 00218 On some system, like NETWARE, strerror(unknown_error) returns a 00219 string 'Unknown Error'. To avoid printing it we try to find the 00220 error string by asking for an impossible big error message. 00221 00222 On Solaris 2.8 it might return NULL 00223 */ 00224 if ((msg= strerror(10000)) == NULL) 00225 msg= "Unknown Error"; 00226 00227 /* 00228 Allocate a buffer for unknown_error since strerror always returns 00229 the same pointer on some platforms such as Windows 00230 */ 00231 unknown_error= malloc(strlen(msg)+1); 00232 strmov(unknown_error, msg); 00233 00234 for ( ; argc-- > 0 ; argv++) 00235 { 00236 00237 found=0; 00238 code=atoi(*argv); 00239 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE 00240 if (ndb_code) 00241 { 00242 if ((ndb_error_string(code, ndb_string, sizeof(ndb_string)) < 0) && 00243 (ndbd_exit_string(code, ndb_string, sizeof(ndb_string)) < 0)) 00244 { 00245 msg= 0; 00246 } 00247 else 00248 msg= ndb_string; 00249 if (msg) 00250 { 00251 if (verbose) 00252 printf("NDB error code %3d: %s\n",code,msg); 00253 else 00254 puts(msg); 00255 } 00256 else 00257 { 00258 fprintf(stderr,"Illegal ndb error code: %d\n",code); 00259 error= 1; 00260 } 00261 found= 1; 00262 msg= 0; 00263 } 00264 else 00265 #endif 00266 msg = strerror(code); 00267 00268 /* 00269 We don't print the OS error message if it is the same as the 00270 unknown_error message we retrieved above, or it starts with 00271 'Unknown Error' (without regard to case). 00272 */ 00273 if (msg && 00274 my_strnncoll(&my_charset_latin1, (const uchar*) msg, 13, 00275 (const uchar*) "Unknown Error", 13) && 00276 (!unknown_error || strcmp(msg, unknown_error))) 00277 { 00278 found=1; 00279 if (verbose) 00280 printf("OS error code %3d: %s\n",code,msg); 00281 else 00282 puts(msg); 00283 } 00284 00285 if (!found) 00286 { 00287 /* Error message still not found, look in handler error codes */ 00288 if (!(msg=get_ha_error_msg(code))) 00289 { 00290 fprintf(stderr,"Illegal error code: %d\n",code); 00291 error=1; 00292 } 00293 else 00294 { 00295 found= 1; 00296 if (verbose) 00297 printf("MySQL error code %3d: %s\n",code,msg); 00298 else 00299 puts(msg); 00300 } 00301 } 00302 } 00303 } 00304 00305 /* if we allocated a buffer for unknown_error, free it now */ 00306 if (unknown_error) 00307 free(unknown_error); 00308 00309 exit(error); 00310 return error; 00311 }
Here is the call graph for this function:

| static void print_version | ( | void | ) | [static] |
Definition at line 119 of file perror.c.
References MACHINE_TYPE, my_progname, PERROR_VERSION, and SYSTEM_TYPE.
00120 { 00121 printf("%s Ver %s, for %s (%s)\n",my_progname,PERROR_VERSION, 00122 SYSTEM_TYPE,MACHINE_TYPE); 00123 }
| static void usage | ( | void | ) | [static] |
Definition at line 126 of file perror.c.
References my_long_options, my_print_help(), my_print_variables(), my_progname, and print_version().
00127 { 00128 print_version(); 00129 puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); 00130 printf("Print a description for a system error code or an error code from\na MyISAM/ISAM/BDB table handler.\n"); 00131 printf("If you want to get the error for a negative error code, you should use\n-- before the first error code to tell perror that there was no more options.\n\n"); 00132 printf("Usage: %s [OPTIONS] [ERRORCODE [ERRORCODE...]]\n",my_progname); 00133 my_print_help(my_long_options); 00134 my_print_variables(my_long_options); 00135 }
Here is the call graph for this function:

HA_ERRORS ha_errlist[] [static] |
struct my_option my_long_options[] [static] |
Initial value:
{
{"help", '?', "Displays this help and exits.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"info", 'I', "Synonym for --help.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"silent", 's', "Only print the error message.", 0, 0, 0, GET_NO_ARG, NO_ARG,
0, 0, 0, 0, 0, 0},
{"verbose", 'v', "Print error code and message (default).", (gptr*) &verbose,
(gptr*) &verbose, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"version", 'V', "Displays version information and exits.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}
my_bool print_all_codes [static] |
1.4.7

