diff options
author | jcole@mugatu.spaceapes.com <> | 2002-05-12 00:20:16 -0500 |
---|---|---|
committer | jcole@mugatu.spaceapes.com <> | 2002-05-12 00:20:16 -0500 |
commit | 54b0d0140cd7145f9df035cddf0f875faf558d7a (patch) | |
tree | a6428d66b41cd38391759ad8aff0e6375e44f4ca /mysys | |
parent | 7b2c9943e2a3b17a3efc00f1a78cbfdaf8e71ce5 (diff) | |
parent | 4945fd4a05dff53f4515226868269e95c742732c (diff) | |
download | mariadb-git-54b0d0140cd7145f9df035cddf0f875faf558d7a.tar.gz |
Merge jcole@work.mysql.com:/home/bk/mysql-4.0
into mugatu.spaceapes.com:/home/jcole/bk/mysql-4.0
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/array.c | 2 | ||||
-rw-r--r-- | mysys/charset.c | 4 | ||||
-rw-r--r-- | mysys/default.c | 2 | ||||
-rw-r--r-- | mysys/hash.c | 2 | ||||
-rw-r--r-- | mysys/my_getopt.c | 224 | ||||
-rw-r--r-- | mysys/my_pthread.c | 18 | ||||
-rw-r--r-- | mysys/my_thr_init.c | 20 | ||||
-rw-r--r-- | mysys/raid.cc | 2 |
8 files changed, 207 insertions, 67 deletions
diff --git a/mysys/array.c b/mysys/array.c index 2420213d454..2a0723fbd69 100644 --- a/mysys/array.c +++ b/mysys/array.c @@ -28,7 +28,7 @@ even if space allocation failed */ -my_bool _init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, +my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, uint init_alloc, uint alloc_increment CALLER_INFO_PROTO) { diff --git a/mysys/charset.c b/mysys/charset.c index 93e8b697904..1001b76f417 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -122,7 +122,7 @@ static my_bool read_charset_index(CS_ID ***charsets, myf myflags) fb.buf[0] = '\0'; fb.p = fb.buf; - if (init_dynamic_array(&cs, sizeof(CS_ID *), 32, 32)) + if (my_init_dynamic_array(&cs, sizeof(CS_ID *), 32, 32)) return TRUE; while (!get_word(&fb, buf) && !get_word(&fb, num_buf)) @@ -180,7 +180,7 @@ static my_bool init_available_charsets(myf myflags) pthread_mutex_lock(&THR_LOCK_charset); if (!cs_info_table.buffer) /* If not initialized */ { - init_dynamic_array(&cs_info_table, sizeof(CHARSET_INFO*), 16, 8); + my_init_dynamic_array(&cs_info_table, sizeof(CHARSET_INFO*), 16, 8); error = read_charset_index(&available_charsets, myflags); } charset_initialized=1; diff --git a/mysys/default.c b/mysys/default.c index d3c1b3815eb..12d7d2e4ed0 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -123,7 +123,7 @@ void load_defaults(const char *conf_file, const char **groups, for (; *groups ; groups++) group.count++; - if (init_dynamic_array(&args, sizeof(char*),*argc, 32)) + if (my_init_dynamic_array(&args, sizeof(char*),*argc, 32)) goto err; if (forced_default_file) { diff --git a/mysys/hash.c b/mysys/hash.c index b3769d1dfb2..eaea6d7503f 100644 --- a/mysys/hash.c +++ b/mysys/hash.c @@ -44,7 +44,7 @@ my_bool _hash_init(HASH *hash,uint size,uint key_offset,uint key_length, DBUG_PRINT("enter",("hash: %lx size: %d",hash,size)); hash->records=0; - if (init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0)) + if (my_init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0)) { hash->free=0; /* Allow call to hash_free */ DBUG_RETURN(TRUE); diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index b17d1463121..f0e289d6af9 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -26,13 +26,18 @@ static int findopt (char *optpat, uint length, static my_bool compare_strings (register const char *s, register const char *t, uint length); static longlong getopt_ll (char *arg, const struct my_option *optp, int *err); +static ulonglong getopt_ull (char *arg, const struct my_option *optp, + int *err); static void init_variables(const struct my_option *options); +static int setval (const struct my_option *opts, char *argument, + my_bool set_maximum_value); +#define DISABLE_OPTION_COUNT 2 /* currently 'skip' and 'disable' below */ -#define DISABLE_OPTION_COUNT 2 - +/* 'disable'-option prefixes must be in the beginning, DISABLE_OPTION_COUNT + is the number of disabling prefixes */ static const char *special_opt_prefix[]= -{"skip", "disable", "enable", "maximum", 0}; +{"skip", "disable", "enable", "maximum", "loose", 0}; char *disabled_my_option= (char*) "0"; @@ -66,15 +71,17 @@ int handle_options(int *argc, char ***argv, char *)) { uint opt_found, argvpos= 0, length, spec_len, i; - int err= 0; - my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used; + my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used, + option_is_loose; char *progname= *(*argv), **pos, *optend, *prev_found; const struct my_option *optp; + int error; LINT_INIT(opt_found); (*argc)--; /* Skip the program name */ (*argv)++; /* --- || ---- */ init_variables(longopts); + for (pos= *argv; *pos; pos++) { char *cur_arg= *pos; @@ -84,6 +91,7 @@ int handle_options(int *argc, char ***argv, must_be_var= 0; set_maximum_value= 0; special_used= 0; + option_is_loose= 0; cur_arg++; /* skip '-' */ if (*cur_arg == 'O') @@ -173,7 +181,7 @@ int handle_options(int *argc, char ***argv, if (!must_be_var) { if (optend) - must_be_var= 1; + must_be_var= 1; /* option is followed by an argument */ for (i= 0; special_opt_prefix[i]; i++) { spec_len= strlen(special_opt_prefix[i]); @@ -185,6 +193,8 @@ int handle_options(int *argc, char ***argv, */ special_used= 1; cur_arg+= (spec_len + 1); + if (!compare_strings(special_opt_prefix[i], "loose", 5)) + option_is_loose= 1; if ((opt_found= findopt(cur_arg, length - (spec_len + 1), &optp, &prev_found))) { @@ -215,14 +225,23 @@ int handle_options(int *argc, char ***argv, if (must_be_var) { fprintf(stderr, - "%s: unknown variable '%s'\n", progname, cur_arg); - return ERR_UNKNOWN_VARIABLE; + "%s: %s: unknown variable '%s'\n", progname, + option_is_loose ? "WARNING" : "ERROR", cur_arg); + if (!option_is_loose) + return ERR_UNKNOWN_VARIABLE; } else { fprintf(stderr, - "%s: unknown option '--%s'\n", progname, cur_arg); - return ERR_UNKNOWN_OPTION; + "%s: %s: unknown option '--%s'\n", progname, + option_is_loose ? "WARNING" : "ERROR", cur_arg); + if (!option_is_loose) + return ERR_UNKNOWN_OPTION; + } + if (option_is_loose) + { + (*argc)--; + continue; } } } @@ -241,11 +260,11 @@ int handle_options(int *argc, char ***argv, return ERR_AMBIGUOUS_OPTION; } } - if (must_be_var && !optp->value) + if (must_be_var && (!optp->value || optp->var_type == GET_BOOL)) { - fprintf(stderr, "%s: argument '%s' is not a variable\n", - progname, *pos); - return ERR_MUST_BE_VARIABLE; + fprintf(stderr, "%s: option '%s' cannot take an argument\n", + progname, optp->name); + return ERR_NO_ARGUMENT_ALLOWED; } if (optp->arg_type == NO_ARG) { @@ -337,6 +356,13 @@ int handle_options(int *argc, char ***argv, /* the other loop will break, because *optend + 1 == 0 */ } } + if ((error= setval(optp, argument, set_maximum_value))) + { + fprintf(stderr, + "%s: Error while setting value '%s' to '%s'\n", + progname, argument, optp->name); + return error; + } get_one_option(optp->id, optp, argument); break; } @@ -351,25 +377,12 @@ int handle_options(int *argc, char ***argv, (*argc)--; /* option handled (short), decrease argument count */ continue; } - if (optp->value) + if ((error= setval(optp, argument, set_maximum_value))) { - gptr *result_pos= (set_maximum_value) ? - optp->u_max_value : optp->value; - - if (!result_pos) - { - fprintf(stderr, - "%s: Can't set a value for %s\n", progname, optp->name); - return ERR_NO_PTR_TO_VARIABLE; - } - if (optp->var_type == GET_LONG) - *((long*) result_pos)= (long) getopt_ll(argument, optp, &err); - else if (optp->var_type == GET_LL) - *((longlong*) result_pos)= getopt_ll(argument, optp, &err); - else if (optp->var_type == GET_STR) - *((char**) result_pos)= argument; - if (err) - return ERR_UNKNOWN_SUFFIX; + fprintf(stderr, + "%s: Error while setting value '%s' to '%s'\n", + progname, argument, optp->name); + return error; } get_one_option(optp->id, optp, argument); @@ -381,6 +394,41 @@ int handle_options(int *argc, char ***argv, return 0; } +/* + function: setval + + Arguments: opts, argument + Will set the option value to given value +*/ + +static int setval (const struct my_option *opts, char *argument, + my_bool set_maximum_value) +{ + int err= 0; + + if (opts->value && argument) + { + gptr *result_pos= (set_maximum_value) ? + opts->u_max_value : opts->value; + + if (!result_pos) + return ERR_NO_PTR_TO_VARIABLE; + + if (opts->var_type == GET_INT || opts->var_type == GET_UINT) + *((int*) result_pos)= (int) getopt_ll(argument, opts, &err); + else if (opts->var_type == GET_LONG || opts->var_type == GET_ULONG) + *((long*) result_pos)= (long) getopt_ll(argument, opts, &err); + else if (opts->var_type == GET_LL) + *((longlong*) result_pos)= getopt_ll(argument, opts, &err); + else if (opts->var_type == GET_ULL) + *((ulonglong*) result_pos)= getopt_ull(argument, opts, &err); + else if (opts->var_type == GET_STR) + *((char**) result_pos)= argument; + if (err) + return ERR_UNKNOWN_SUFFIX; + } + return 0; +} /* function: findopt @@ -436,25 +484,20 @@ static my_bool compare_strings(register const char *s, register const char *t, return 0; } +/* + function: eval_num_suffix -/* - function: getopt_ll - - Evaluates and returns the value that user gave as an argument - to a variable. Recognizes (case insensitive) K as KILO, M as MEGA - and G as GIGA bytes. Some values must be in certain blocks, as - defined in the given my_option struct, this function will check - that those values are honored. - In case of an error, set error value in *err. + Transforms a number with a suffix to real number. Suffix can + be k|K for kilo, m|M for mega or g|G for giga. */ -static longlong getopt_ll (char *arg, const struct my_option *optp, int *err) +static longlong eval_num_suffix (char *argument, int *error, char *option_name) { char *endchar; longlong num; - *err= 0; - num= strtoll(arg, &endchar, 10); + *error= 0; + num= strtoll(argument, &endchar, 10); if (*endchar == 'k' || *endchar == 'K') num*= 1024L; else if (*endchar == 'm' || *endchar == 'M') @@ -465,9 +508,29 @@ static longlong getopt_ll (char *arg, const struct my_option *optp, int *err) { fprintf(stderr, "Unknown suffix '%c' used for variable '%s' (value '%s')\n", - *endchar, optp->name, arg); - *err= 1; + *endchar, option_name, argument); + *error= 1; + return 0; } + return num; +} + +/* + function: getopt_ll + + Evaluates and returns the value that user gave as an argument + to a variable. Recognizes (case insensitive) K as KILO, M as MEGA + and G as GIGA bytes. Some values must be in certain blocks, as + defined in the given my_option struct, this function will check + that those values are honored. + In case of an error, set error value in *err. +*/ + +static longlong getopt_ll (char *arg, const struct my_option *optp, int *err) +{ + longlong num; + + num= eval_num_suffix(arg, err, (char*) optp->name); if (num < (longlong) optp->min_value) num= (longlong) optp->min_value; else if (num > 0 && (ulonglong) num > (ulonglong) (ulong) optp->max_value @@ -480,6 +543,29 @@ static longlong getopt_ll (char *arg, const struct my_option *optp, int *err) 1L)); } +/* + function: getopt_ull + + This is the same as getopt_ll, but is meant for unsigned long long + values. +*/ + +static ulonglong getopt_ull (char *arg, const struct my_option *optp, int *err) +{ + ulonglong num; + + num= eval_num_suffix(arg, err, (char*) optp->name); + if (num < (ulonglong) optp->min_value) + num= (ulonglong) optp->min_value; + else if (num > 0 && (ulonglong) num > (ulonglong) (ulong) optp->max_value + && optp->max_value) // if max value is not set -> no upper limit + num= (ulonglong) (ulong) optp->max_value; + num= ((num - (ulonglong) optp->sub_size) / (optp->block_size ? + (ulonglong) optp->block_size : + 1L)); + return (ulonglong) (num * (optp->block_size ? (ulonglong) optp->block_size : + 1L)); +} /* function: init_variables @@ -493,12 +579,24 @@ static void init_variables(const struct my_option *options) { if (options->value) { - if (options->var_type == GET_LONG) + if (options->var_type == GET_INT) + *((int*) options->u_max_value)= *((int*) options->value)= + (int) options->def_value; + else if (options->var_type == GET_UINT) + *((uint*) options->u_max_value)= *((uint*) options->value)= + (uint) options->def_value; + else if (options->var_type == GET_LONG) *((long*) options->u_max_value)= *((long*) options->value)= (long) options->def_value; + else if (options->var_type == GET_ULONG) + *((ulong*) options->u_max_value)= *((ulong*) options->value)= + (ulong) options->def_value; else if (options->var_type == GET_LL) *((longlong*) options->u_max_value)= *((longlong*) options->value)= - options->def_value; + (longlong) options->def_value; + else if (options->var_type == GET_ULL) + *((ulonglong*) options->u_max_value)= *((ulonglong*) options->value)= + (ulonglong) options->def_value; } } } @@ -604,6 +702,20 @@ void my_print_variables(const struct my_option *options) else printf("(No default value)\n"); } + else if (optp->var_type == GET_INT) + { + if (!optp->def_value && !*((int*) optp->value)) + printf("(No default value)\n"); + else + printf("%d\n", *((int*) optp->value)); + } + else if (optp->var_type == GET_UINT) + { + if (!optp->def_value && !*((uint*) optp->value)) + printf("(No default value)\n"); + else + printf("%d\n", *((uint*) optp->value)); + } else if (optp->var_type == GET_LONG) { if (!optp->def_value && !*((long*) optp->value)) @@ -611,13 +723,27 @@ void my_print_variables(const struct my_option *options) else printf("%lu\n", *((long*) optp->value)); } - else + else if (optp->var_type == GET_ULONG) + { + if (!optp->def_value && !*((ulong*) optp->value)) + printf("(No default value)\n"); + else + printf("%lu\n", *((ulong*) optp->value)); + } + else if (optp->var_type == GET_LL) { if (!optp->def_value && !*((longlong*) optp->value)) printf("(No default value)\n"); else printf("%s\n", llstr(*((longlong*) optp->value), buff)); } + else if (optp->var_type == GET_ULL) + { + if (!optp->def_value && !*((ulonglong*) optp->value)) + printf("(No default value)\n"); + else + printf("%s\n", longlong2str(*((ulonglong*) optp->value), buff, 10)); + } } } } diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index 37c18a32451..3a448864b21 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -410,9 +410,23 @@ int my_pthread_cond_init(pthread_cond_t *mp, const pthread_condattr_t *attr) #endif +/* Change functions on HP to work according to POSIX */ + +#ifdef HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT +#undef pthread_cond_timedwait + +int my_pthread_cond_timedwait(pthread_cond_t *cond, + pthread_mutex_t *mutex, + struct timespec *abstime) +{ + int error=pthread_cond_timedwait(cond,mutex,abstime); + return error == EAGAIN ? ETIMEDOUT : error; +} +#endif /* HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT */ + /* -** Emulate SOLARIS style calls, not because it's better, but just to make the -** usage of getbostbyname_r simpler. + Emulate SOLARIS style calls, not because it's better, but just to make the + usage of getbostbyname_r simpler. */ #if !defined(my_gethostbyname_r) && defined(HAVE_GETHOSTBYNAME_R) diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 5b137df20f8..8e6fdbbbec5 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -105,7 +105,9 @@ static long thread_id=0; my_bool my_thread_init(void) { struct st_my_thread_var *tmp; -#ifdef EXTRA_DEBUG + my_bool error=0; + +#ifdef EXTRA_DEBUG_THREADS fprintf(stderr,"my_thread_init(): thread_id=%ld\n",pthread_self()); #endif #if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX) @@ -117,16 +119,14 @@ my_bool my_thread_init(void) { #ifdef EXTRA_DEBUG fprintf(stderr,"my_thread_init() called more than once in thread %ld\n", - pthread_self()); + pthread_self()); #endif - pthread_mutex_unlock(&THR_LOCK_lock); - return 0; /* Safequard */ + goto end; } - if (!(tmp=(struct st_my_thread_var *) - calloc(1, sizeof(struct st_my_thread_var)))) + if (!(tmp= (struct st_my_thread_var *) calloc(1, sizeof(*tmp)))) { - pthread_mutex_unlock(&THR_LOCK_lock); - return 1; + error= 1; + goto end; } pthread_setspecific(THR_KEY_mysys,tmp); @@ -146,13 +146,13 @@ end: #if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX) pthread_mutex_unlock(&THR_LOCK_lock); #endif - return 0; + return error; } void my_thread_end(void) { struct st_my_thread_var *tmp=my_thread_var; -#ifdef EXTRA_DEBUG +#ifdef EXTRA_DEBUG_THREADS fprintf(stderr,"my_thread_end(): tmp=%p,thread_id=%ld\n", tmp,pthread_self()); #endif diff --git a/mysys/raid.cc b/mysys/raid.cc index 72d3b2074be..6196e1f1aa6 100644 --- a/mysys/raid.cc +++ b/mysys/raid.cc @@ -94,7 +94,7 @@ extern "C" { void init_raid(void) { /* Allocate memory for global file to raid map */ - init_dynamic_array(&RaidFd::_raid_map, sizeof(RaidFd*), 4096, 1024); + my_init_dynamic_array(&RaidFd::_raid_map, sizeof(RaidFd*), 4096, 1024); } void end_raid(void) { |