summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/Makefile.am5
-rw-r--r--mysys/mf_iocache.c2
-rw-r--r--mysys/mf_strip.c (renamed from mysys/mf_stripp.c)6
-rw-r--r--mysys/my_gethostbyname.c9
-rw-r--r--mysys/my_getopt.c138
-rw-r--r--mysys/my_pthread.c1
-rw-r--r--mysys/raid2.c31
7 files changed, 118 insertions, 74 deletions
diff --git a/mysys/Makefile.am b/mysys/Makefile.am
index 9e458331619..31b0947af9f 100644
--- a/mysys/Makefile.am
+++ b/mysys/Makefile.am
@@ -35,7 +35,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\
my_error.c errors.c my_div.c my_messnc.c \
mf_format.c mf_same.c mf_dirname.c mf_fn_ext.c \
my_symlink.c my_symlink2.c \
- mf_pack.c mf_unixpath.c mf_stripp.c \
+ mf_pack.c mf_unixpath.c mf_strip.c \
mf_casecnv.c mf_soundex.c mf_wcomp.c mf_wfile.c \
mf_qsort.c mf_qsort2.c mf_sort.c \
ptr_cmp.c mf_radix.c queues.c \
@@ -45,7 +45,8 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\
my_chsize.c my_lread.c my_lwrite.c my_clock.c \
my_quick.c my_lockmem.c my_static.c \
my_getopt.c getvar.c my_mkdir.c \
- default.c my_compress.c checksum.c raid.cc my_net.c \
+ default.c my_compress.c checksum.c raid.cc \
+ my_net.c \
my_vsnprintf.c charset.c my_bitmap.c my_bit.c md5.c \
my_gethostbyname.c
EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \
diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index a0247003a81..34873d107af 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -122,8 +122,6 @@ int init_io_cache(IO_CACHE *info, File file, uint cachesize,
info->pos_in_file= seek_offset;
info->pre_close = info->pre_read = info->post_read = 0;
info->arg = 0;
- info->init_count++; /* we assume the user had set it to 0 prior to
- first call */
info->alloced_buffer = 0;
info->buffer=0;
info->seek_not_done= test(file >= 0);
diff --git a/mysys/mf_stripp.c b/mysys/mf_strip.c
index d2fd171ec8c..ef2aab2c0a3 100644
--- a/mysys/mf_stripp.c
+++ b/mysys/mf_strip.c
@@ -19,11 +19,11 @@
#include "mysys_priv.h"
/*
- stripp_sp(my_string str)
+ strip_sp(my_string str)
Strips end-space from string and returns new length.
*/
-size_s stripp_sp(register my_string str)
+size_s strip_sp(register my_string str)
{
reg2 my_string found;
reg3 my_string start;
@@ -43,4 +43,4 @@ size_s stripp_sp(register my_string str)
}
*found= '\0'; /* Stripp at first space */
return (size_s) (found-start);
-} /* stripp_sp */
+} /* strip_sp */
diff --git a/mysys/my_gethostbyname.c b/mysys/my_gethostbyname.c
index 76a0a780dd3..1380257f660 100644
--- a/mysys/my_gethostbyname.c
+++ b/mysys/my_gethostbyname.c
@@ -18,21 +18,18 @@
/* Thread safe version of gethostbyname_r() */
#include "mysys_priv.h"
+#ifdef THREAD
#include "my_pthread.h"
+#endif
#include <assert.h>
-#include <my_net.h>
#if !defined(MSDOS) && !defined(__WIN__)
#include <netdb.h>
#endif
+#include <my_net.h>
/* This file is not needed if my_gethostbyname_r is a macro */
#if !defined(my_gethostbyname_r)
-#ifndef THREAD
-#define pthread_mutex_lock(A)
-#define pthread_mutex_unlock(A)
-#endif
-
/*
Emulate SOLARIS style calls, not because it's better, but just to make the
usage of getbostbyname_r simpler.
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 80904fb46f6..12af811a0c8 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -20,6 +20,7 @@
#include <my_getopt.h>
#include <assert.h>
#include <my_sys.h>
+#include <mysys_err.h>
static int findopt (char *optpat, uint length,
const struct my_option **opt_res,
@@ -42,17 +43,11 @@ static const char *special_opt_prefix[]=
char *disabled_my_option= (char*) "0";
-/* Return error values from handle_options */
+/* This is a flag that can be set in client programs. 0 means that
+ my_getopt will not print error messages, but the client should do
+ it by itself */
-#define ERR_UNKNOWN_OPTION 1
-#define ERR_AMBIGUOUS_OPTION 2
-#define ERR_NO_ARGUMENT_ALLOWED 3
-#define ERR_ARGUMENT_REQUIRED 4
-#define ERR_VAR_PREFIX_NOT_UNIQUE 5
-#define ERR_UNKNOWN_VARIABLE 6
-#define ERR_OUT_OF_MEMORY 7
-#define ERR_UNKNOWN_SUFFIX 8
-#define ERR_NO_PTR_TO_VARIABLE 9
+my_bool my_getopt_print_errors= 1;
/*
@@ -73,7 +68,7 @@ int handle_options(int *argc, char ***argv,
{
uint opt_found, argvpos= 0, length, spec_len, i;
my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used,
- option_is_loose;
+ option_is_loose, option_used= 0;
char *progname= *(*argv), **pos, *optend, *prev_found;
const struct my_option *optp;
int error;
@@ -89,6 +84,7 @@ int handle_options(int *argc, char ***argv,
if (cur_arg[0] == '-' && cur_arg[1] && !end_of_options) /* must be opt */
{
char *argument= 0;
+ option_used= 1;
must_be_var= 0;
set_maximum_value= 0;
special_used= 0;
@@ -106,9 +102,10 @@ int handle_options(int *argc, char ***argv,
/* the argument must be in next argv */
if (!*++pos)
{
- fprintf(stderr, "%s: Option '-O' requires an argument\n",
- progname);
- return ERR_ARGUMENT_REQUIRED;
+ if (my_getopt_print_errors)
+ fprintf(stderr, "%s: Option '-O' requires an argument\n",
+ progname);
+ return EXIT_ARGUMENT_REQUIRED;
}
cur_arg= *pos;
(*argc)--;
@@ -128,10 +125,11 @@ int handle_options(int *argc, char ***argv,
cur_arg+= 14;
if (!*cur_arg)
{
- fprintf(stderr,
- "%s: Option '--set-variable' requires an argument\n",
- progname);
- return ERR_ARGUMENT_REQUIRED;
+ if (my_getopt_print_errors)
+ fprintf(stderr,
+ "%s: Option '--set-variable' requires an argument\n",
+ progname);
+ return EXIT_ARGUMENT_REQUIRED;
}
}
else if (cur_arg[14]) /* garbage, or another option. break out */
@@ -141,10 +139,11 @@ int handle_options(int *argc, char ***argv,
/* the argument must be in next argv */
if (!*++pos)
{
- fprintf(stderr,
- "%s: Option '--set-variable' requires an argument\n",
- progname);
- return ERR_ARGUMENT_REQUIRED;
+ if (my_getopt_print_errors)
+ fprintf(stderr,
+ "%s: Option '--set-variable' requires an argument\n",
+ progname);
+ return EXIT_ARGUMENT_REQUIRED;
}
cur_arg= *pos;
(*argc)--;
@@ -200,11 +199,12 @@ int handle_options(int *argc, char ***argv,
{
if (opt_found > 1)
{
- fprintf(stderr,
- "%s: ambiguous option '--%s-%s' (--%s-%s)\n",
- progname, special_opt_prefix[i], cur_arg,
- special_opt_prefix[i], prev_found);
- return ERR_AMBIGUOUS_OPTION;
+ if (my_getopt_print_errors)
+ fprintf(stderr,
+ "%s: ambiguous option '--%s-%s' (--%s-%s)\n",
+ progname, special_opt_prefix[i], cur_arg,
+ special_opt_prefix[i], prev_found);
+ return EXIT_AMBIGUOUS_OPTION;
}
if (i < DISABLE_OPTION_COUNT)
optend= disabled_my_option;
@@ -224,19 +224,21 @@ int handle_options(int *argc, char ***argv,
{
if (must_be_var)
{
- fprintf(stderr,
- "%s: %s: unknown variable '%s'\n", progname,
- option_is_loose ? "WARNING" : "ERROR", cur_arg);
+ if (my_getopt_print_errors)
+ fprintf(stderr,
+ "%s: %s: unknown variable '%s'\n", progname,
+ option_is_loose ? "WARNING" : "ERROR", cur_arg);
if (!option_is_loose)
- return ERR_UNKNOWN_VARIABLE;
+ return EXIT_UNKNOWN_VARIABLE;
}
else
{
- fprintf(stderr,
- "%s: %s: unknown option '--%s'\n", progname,
- option_is_loose ? "WARNING" : "ERROR", cur_arg);
+ if (my_getopt_print_errors)
+ fprintf(stderr,
+ "%s: %s: unknown option '--%s'\n", progname,
+ option_is_loose ? "WARNING" : "ERROR", cur_arg);
if (!option_is_loose)
- return ERR_UNKNOWN_OPTION;
+ return EXIT_UNKNOWN_OPTION;
}
if (option_is_loose)
{
@@ -249,30 +251,34 @@ int handle_options(int *argc, char ***argv,
{
if (must_be_var)
{
- fprintf(stderr, "%s: variable prefix '%s' is not unique\n",
- progname, cur_arg);
- return ERR_VAR_PREFIX_NOT_UNIQUE;
+ if (my_getopt_print_errors)
+ fprintf(stderr, "%s: variable prefix '%s' is not unique\n",
+ progname, cur_arg);
+ return EXIT_VAR_PREFIX_NOT_UNIQUE;
}
else
{
- fprintf(stderr, "%s: ambiguous option '--%s' (%s, %s)\n",
- progname, cur_arg, prev_found, optp->name);
- return ERR_AMBIGUOUS_OPTION;
+ if (my_getopt_print_errors)
+ fprintf(stderr, "%s: ambiguous option '--%s' (%s, %s)\n",
+ progname, cur_arg, prev_found, optp->name);
+ return EXIT_AMBIGUOUS_OPTION;
}
}
if (must_be_var && (!optp->value || optp->var_type == GET_BOOL))
{
- fprintf(stderr, "%s: option '%s' cannot take an argument\n",
- progname, optp->name);
- return ERR_NO_ARGUMENT_ALLOWED;
+ if (my_getopt_print_errors)
+ fprintf(stderr, "%s: option '%s' cannot take an argument\n",
+ progname, optp->name);
+ return EXIT_NO_ARGUMENT_ALLOWED;
}
if (optp->arg_type == NO_ARG)
{
if (optend && !special_used)
{
- fprintf(stderr, "%s: option '--%s' cannot take an argument\n",
- progname, optp->name);
- return ERR_NO_ARGUMENT_ALLOWED;
+ if (my_getopt_print_errors)
+ fprintf(stderr, "%s: option '--%s' cannot take an argument\n",
+ progname, optp->name);
+ return EXIT_NO_ARGUMENT_ALLOWED;
}
if (optp->var_type == GET_BOOL)
{
@@ -306,9 +312,10 @@ int handle_options(int *argc, char ***argv,
/* Check if there are more arguments after this one */
if (!*++pos)
{
- fprintf(stderr, "%s: option '--%s' requires an argument\n",
- progname, optp->name);
- return ERR_ARGUMENT_REQUIRED;
+ if (my_getopt_print_errors)
+ fprintf(stderr, "%s: option '--%s' requires an argument\n",
+ progname, optp->name);
+ return EXIT_ARGUMENT_REQUIRED;
}
argument= *pos;
(*argc)--;
@@ -318,8 +325,9 @@ int handle_options(int *argc, char ***argv,
}
else /* must be short option */
{
- for (optend= cur_arg; *optend; optend++, opt_found= 0)
+ for (optend= cur_arg; *optend; optend++)
{
+ opt_found= 0;
for (optp= longopts; optp->id; optp++)
{
if (optp->id == (int) (uchar) *optend)
@@ -329,7 +337,6 @@ int handle_options(int *argc, char ***argv,
if (optp->var_type == GET_BOOL && optp->arg_type == NO_ARG)
{
*((my_bool*) optp->value)= (my_bool) 1;
- (*argc)--;
continue; // For GET_BOOL get_one_option() shouldn't be called
}
else if (optp->arg_type == REQUIRED_ARG ||
@@ -347,9 +354,11 @@ int handle_options(int *argc, char ***argv,
/* Check if there are more arguments after this one */
if (!*++pos)
{
- fprintf(stderr, "%s: option '-%c' requires an argument\n",
- progname, optp->id);
- return ERR_ARGUMENT_REQUIRED;
+ if (my_getopt_print_errors)
+ fprintf(stderr,
+ "%s: option '-%c' requires an argument\n",
+ progname, optp->id);
+ return EXIT_ARGUMENT_REQUIRED;
}
argument= *pos;
(*argc)--;
@@ -369,9 +378,10 @@ int handle_options(int *argc, char ***argv,
}
if (!opt_found)
{
- fprintf(stderr,
- "%s: unknown option '-%c'\n", progname, *cur_arg);
- return ERR_UNKNOWN_OPTION;
+ if (my_getopt_print_errors)
+ fprintf(stderr,
+ "%s: unknown option '-%c'\n", progname, *optend);
+ return EXIT_UNKNOWN_OPTION;
}
}
(*argc)--; /* option handled (short), decrease argument count */
@@ -391,6 +401,12 @@ int handle_options(int *argc, char ***argv,
else /* non-option found */
(*argv)[argvpos++]= cur_arg;
}
+ /* Destroy the first, already handled option, so that programs that look
+ for arguments in 'argv', without checking 'argc', know when to stop.
+ Items in argv, before the destroyed one, are all non-option -arguments
+ to the program, yet to be (possibly) handled. */
+ if (option_used)
+ (*argv)[argvpos]= 0;
return 0;
}
@@ -412,7 +428,7 @@ static int setval (const struct my_option *opts, char *argument,
opts->u_max_value : opts->value;
if (!result_pos)
- return ERR_NO_PTR_TO_VARIABLE;
+ return EXIT_NO_PTR_TO_VARIABLE;
switch (opts->var_type) {
case GET_INT:
@@ -437,13 +453,13 @@ static int setval (const struct my_option *opts, char *argument,
my_free((*(char**) result_pos),
MYF(MY_WME | MY_FAE));
if (!(*((char**) result_pos)= my_strdup(argument, MYF(MY_WME))))
- return ERR_OUT_OF_MEMORY;
+ return EXIT_OUT_OF_MEMORY;
break;
default: /* dummy default to avoid compiler warnings */
break;
}
if (err)
- return ERR_UNKNOWN_SUFFIX;
+ return EXIT_UNKNOWN_SUFFIX;
}
return 0;
}
diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c
index 747a07e71b2..e1345b96627 100644
--- a/mysys/my_pthread.c
+++ b/mysys/my_pthread.c
@@ -419,6 +419,7 @@ int my_pthread_cond_init(pthread_cond_t *mp, const pthread_condattr_t *attr)
****************************************************************************/
#if defined(HPUX) || defined(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)
diff --git a/mysys/raid2.c b/mysys/raid2.c
new file mode 100644
index 00000000000..94b085b0074
--- /dev/null
+++ b/mysys/raid2.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2002 MySQL AB
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA */
+
+/*
+ RAID support for MySQL. For full comments, check raid.cc
+ This is in a separate file to not cause problems on OS that can't
+ put C++ files in archives.
+*/
+
+#include "mysys_priv.h"
+
+const char *raid_type_string[]={"none","striped"};
+
+const char *my_raid_type(int raid_type)
+{
+ return raid_type_string[raid_type];
+}