summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorunknown <monty@narttu.mysql.fi>2003-09-03 19:53:08 +0300
committerunknown <monty@narttu.mysql.fi>2003-09-03 19:53:08 +0300
commit35af1442b6492f0962dd48f8dbcbb995a0f5f7e1 (patch)
treea927f30b44fb1ffd56321ff4510effc73a2e493e /mysys
parentf6daa5c358d6c8f697bda11b5315d307c23f5633 (diff)
parent0fa5279543d20c0d0c9ef6a1835c7f5056f0a997 (diff)
downloadmariadb-git-35af1442b6492f0962dd48f8dbcbb995a0f5f7e1.tar.gz
merge
BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union client/mysqldump.c: Auto merged include/my_sys.h: Auto merged include/mysql_com.h: Auto merged isam/open.c: Auto merged libmysql/libmysql.c: Auto merged mysql-test/r/isam.result: Auto merged mysql-test/r/myisam.result: Auto merged mysql-test/r/rpl_loaddata.result: Auto merged mysql-test/r/rpl_log.result: Auto merged mysql-test/r/show_check.result: Auto merged mysql-test/t/myisam.test: Auto merged sql/ha_myisam.cc: Auto merged sql/item.h: Auto merged sql/item_func.cc: Auto merged sql/item_func.h: Auto merged sql/item_sum.cc: Auto merged sql/mysql_priv.h: Auto merged sql/mysqld.cc: Auto merged sql/repl_failsafe.cc: Auto merged sql/set_var.cc: Auto merged sql/slave.cc: Auto merged sql/slave.h: Auto merged sql/sql_class.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_insert.cc: Auto merged sql/sql_parse.cc: Auto merged sql/sql_repl.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_show.cc: Auto merged sql/share/portuguese/errmsg.txt: Auto merged sql/share/spanish/errmsg.txt: Auto merged sql/sql_table.cc: Auto merged sql/sql_union.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/handler.cc: Merge sql/sql_acl.cc: Merge and code cleanup of acl_getroot()
Diffstat (limited to 'mysys')
-rw-r--r--mysys/default.c148
-rw-r--r--mysys/mf_iocache.c14
-rw-r--r--mysys/my_chsize.c109
-rw-r--r--mysys/my_getopt.c3
-rw-r--r--mysys/my_pthread.c14
5 files changed, 187 insertions, 101 deletions
diff --git a/mysys/default.c b/mysys/default.c
index 9f7181b7da9..8bdf8d4f741 100644
--- a/mysys/default.c
+++ b/mysys/default.c
@@ -15,22 +15,22 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/****************************************************************************
-** Add all options from files named "group".cnf from the default_directories
-** before the command line arguments.
-** On Windows defaults will also search in the Windows directory for a file
-** called 'group'.ini
-** As long as the program uses the last argument for conflicting
-** options one only have to add a call to "load_defaults" to enable
-** use of default values.
-** pre- and end 'blank space' are removed from options and values. The
-** following escape sequences are recognized in values: \b \t \n \r \\
-**
-** The following arguments are handled automaticly; If used, they must be
-** first argument on the command line!
-** --no-defaults ; no options are read.
-** --defaults-file=full-path-to-default-file ; Only this file will be read.
-** --defaults-extra-file=full-path-to-default-file ; Read this file before ~/
-** --print-defaults ; Print the modified command line and exit
+ Add all options from files named "group".cnf from the default_directories
+ before the command line arguments.
+ On Windows defaults will also search in the Windows directory for a file
+ called 'group'.ini
+ As long as the program uses the last argument for conflicting
+ options one only have to add a call to "load_defaults" to enable
+ use of default values.
+ pre- and end 'blank space' are removed from options and values. The
+ following escape sequences are recognized in values: \b \t \n \r \\
+
+ The following arguments are handled automaticly; If used, they must be
+ first argument on the command line!
+ --no-defaults ; no options are read.
+ --defaults-file=full-path-to-default-file ; Only this file will be read.
+ --defaults-extra-file=full-path-to-default-file ; Read this file before ~/
+ --print-defaults ; Print the modified command line and exit
****************************************************************************/
#include "mysys_priv.h"
@@ -66,13 +66,46 @@ NullS,
#define windows_ext ".ini"
#endif
-static my_bool search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc,
- const char *dir, const char *config_file,
- const char *ext, TYPELIB *group);
+static int search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc,
+ const char *dir, const char *config_file,
+ const char *ext, TYPELIB *group);
static char *remove_end_comment(char *ptr);
-void load_defaults(const char *conf_file, const char **groups,
+
+/*
+ Read options from configurations files
+
+ SYNOPSIS
+ load_defaults()
+ conf_file Basename for configuration file to search for.
+ If this is a path, then only this file is read.
+ groups Which [group] entrys to read.
+ Points to an null terminated array of pointers
+ argc Pointer to argc of original program
+ argv Pointer to argv of original program
+
+ IMPLEMENTATION
+
+ Read options from configuration files and put them BEFORE the arguments
+ that are already in argc and argv. This way the calling program can
+ easily command line options override options in configuration files
+
+ NOTES
+ In case of fatal error, the function will print a warning and do
+ exit(1)
+
+ To free used memory one should call free_defaults() with the argument
+ that was put in *argv
+
+ RETURN
+ 0 ok
+ 1 The given conf_file didn't exists
+ 2 The given conf_file was not a normal readable file
+*/
+
+
+int load_defaults(const char *conf_file, const char **groups,
int *argc, char ***argv)
{
DYNAMIC_ARRAY args;
@@ -80,6 +113,7 @@ void load_defaults(const char *conf_file, const char **groups,
TYPELIB group;
my_bool found_print_defaults=0;
uint args_used=0;
+ int error= 0;
MEM_ROOT alloc;
char *ptr,**res;
DBUG_ENTER("load_defaults");
@@ -100,7 +134,7 @@ void load_defaults(const char *conf_file, const char **groups,
(*argc)--;
*argv=res;
*(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */
- DBUG_VOID_RETURN;
+ DBUG_RETURN(0);
}
/* Check if we want to force the use a specific default file */
@@ -129,14 +163,14 @@ void load_defaults(const char *conf_file, const char **groups,
goto err;
if (forced_default_file)
{
- if (search_default_file(&args, &alloc, "", forced_default_file, "",
- &group))
+ if ((error= search_default_file(&args, &alloc, "",
+ forced_default_file, "", &group)) < 0)
goto err;
}
else if (dirname_length(conf_file))
{
- if (search_default_file(&args, &alloc, NullS, conf_file, default_ext,
- &group))
+ if ((error= search_default_file(&args, &alloc, NullS, conf_file,
+ default_ext, &group)) < 0)
goto err;
}
else
@@ -144,29 +178,36 @@ void load_defaults(const char *conf_file, const char **groups,
#ifdef __WIN__
char system_dir[FN_REFLEN];
GetWindowsDirectory(system_dir,sizeof(system_dir));
- if (search_default_file(&args, &alloc, system_dir, conf_file, windows_ext,
- &group))
+ if ((search_default_file(&args, &alloc, system_dir, conf_file,
+ windows_ext, &group)))
goto err;
#endif
#if defined(__EMX__) || defined(OS2)
if (getenv("ETC") &&
- search_default_file(&args, &alloc, getenv("ETC"), conf_file,
- default_ext, &group))
+ (search_default_file(&args, &alloc, getenv("ETC"), conf_file,
+ default_ext, &group)) < 0)
goto err;
#endif
for (dirs=default_directories ; *dirs; dirs++)
{
- int error=0;
if (**dirs)
- error=search_default_file(&args, &alloc, *dirs, conf_file,
- default_ext, &group);
+ {
+ if (search_default_file(&args, &alloc, *dirs, conf_file,
+ default_ext, &group) < 0)
+ goto err;
+ }
else if (defaults_extra_file)
- error=search_default_file(&args, &alloc, NullS, defaults_extra_file,
- default_ext, &group);
- if (error)
- goto err;
+ {
+ if (search_default_file(&args, &alloc, NullS, defaults_extra_file,
+ default_ext, &group) < 0)
+ goto err; /* Fatal error */
+ }
}
}
+ /*
+ Here error contains <> 0 only if we have a fully specified conf_file
+ or a forced default file
+ */
if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
(args.elements + *argc +1) *sizeof(char*))))
goto err;
@@ -202,12 +243,12 @@ void load_defaults(const char *conf_file, const char **groups,
for (i=1 ; i < *argc ; i++)
printf("%s ", (*argv)[i]);
puts("");
- exit(1);
+ exit(0);
}
- DBUG_VOID_RETURN;
+ DBUG_RETURN(error);
err:
- fprintf(stderr,"Program aborted\n");
+ fprintf(stderr,"Fatal error in defaults handling. Program aborted\n");
exit(1);
}
@@ -220,9 +261,28 @@ void free_defaults(char **argv)
}
-static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
- const char *dir, const char *config_file,
- const char *ext, TYPELIB *group)
+/*
+ Open a configuration file (if exists) and read given options from it
+
+ SYNOPSIS
+ search_default_file()
+ args Store pointer to found options here
+ alloc Allocate strings in this object
+ dir directory to read
+ config_file Name of configuration file
+ ext Extension for configuration file
+ group groups to read
+
+ RETURN
+ 0 Success
+ -1 Fatal error, abort
+ 1 File not found (Warning)
+ 2 File is not a regular file (Warning)
+*/
+
+static int search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
+ const char *dir, const char *config_file,
+ const char *ext, TYPELIB *group)
{
char name[FN_REFLEN+10],buff[4096],*ptr,*end,*value,*tmp;
FILE *fp;
@@ -247,7 +307,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
{
MY_STAT stat_info;
if (!my_stat(name,&stat_info,MYF(0)))
- return 0;
+ return 1;
/*
Ignore world-writable regular files.
This is mainly done to protect us to not read a file created by
@@ -364,7 +424,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
err:
my_fclose(fp,MYF(0));
- return 1;
+ return -1; /* Fatal error */
}
diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index 0f35ee048bb..d96d4c0db3c 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -988,6 +988,20 @@ end:
}
+int my_b_safe_write(IO_CACHE *info, const byte *Buffer, uint Count)
+{
+ /*
+ Sasha: We are not writing this with the ? operator to avoid hitting
+ a possible compiler bug. At least gcc 2.95 cannot deal with
+ several layers of ternary operators that evaluated comma(,) operator
+ expressions inside - I do have a test case if somebody wants it
+ */
+ if (info->type == SEQ_READ_APPEND)
+ return my_b_append(info, Buffer, Count);
+ return my_b_write(info, Buffer, Count);
+}
+
+
/*
Write a block to disk where part of the data may be inside the record
buffer. As all write calls to the data goes through the cache,
diff --git a/mysys/my_chsize.c b/mysys/my_chsize.c
index 06e8f159f4a..8e46b0808c0 100644
--- a/mysys/my_chsize.c
+++ b/mysys/my_chsize.c
@@ -30,74 +30,83 @@
MyFlags Flags
DESCRIPTION
- my_chsize() truncates file if shorter, else fill with the filler character
+ my_chsize() truncates file if shorter else fill with the filler character
RETURN VALUE
0 Ok
1 Error
*/
-
int my_chsize(File fd, my_off_t newlength, int filler, myf MyFlags)
{
+ my_off_t oldsize;
+ char buff[IO_SIZE];
DBUG_ENTER("my_chsize");
DBUG_PRINT("my",("fd: %d length: %lu MyFlags: %d",fd,(ulong) newlength,
MyFlags));
-#ifdef HAVE_CHSIZE
- if (chsize(fd,(off_t) newlength))
+ oldsize = my_seek(fd, 0L, MY_SEEK_END, MYF(MY_WME+MY_FAE));
+ DBUG_PRINT("info",("old_size: %ld", (ulong) oldsize));
+
+ if (oldsize > newlength)
+#if defined(HAVE_SETFILEPOINTER)
+ /* This is for the moment only true on windows */
{
- DBUG_PRINT("error",("errno: %d",errno));
- my_errno=errno;
- if (MyFlags & MY_WME)
- my_error(EE_CANT_CHSIZE,MYF(ME_BELL+ME_WAITTANG),errno);
- DBUG_RETURN(1);
+ HANDLE win_file= (HANDLE) _get_osfhandle(fd);
+ long length_low, length_high;
+ length_low= (long) (ulong) newlength;
+ length_high= (long) ((ulonglong) newlength >> 32);
+ if (SetFilePointer(win_file, length_low, &length_high, FILE_BEGIN))
+ {
+ if (SetEndOfFile(win_file))
+ DBUG_RETURN(0);
+ }
+ my_errno= errno;
+ goto err;
}
- DBUG_RETURN(0);
-#else
- /* if file is shorter, expand with null, else fill unused part with null */
+#elif defined(HAVE_FTRUNCATE)
{
- my_off_t oldsize;
- char buff[IO_SIZE];
-
- oldsize = my_seek(fd, 0L, MY_SEEK_END, MYF(MY_WME+MY_FAE));
- DBUG_PRINT("info",("old_size: %ld", (ulong) oldsize));
-
-#ifdef HAVE_FTRUNCATE
- if (oldsize > newlength)
+ if (ftruncate(fd, (off_t) newlength))
{
- if (ftruncate(fd, (off_t) newlength))
- {
- my_errno=errno;
- DBUG_PRINT("error",("errno: %d",errno));
- if (MyFlags & MY_WME)
- my_error(EE_CANT_CHSIZE, MYF(ME_BELL+ME_WAITTANG), errno);
- DBUG_RETURN(1);
- }
- DBUG_RETURN(0);
- }
-#else
- if (oldsize > newlength)
- { /* Fill diff with null */
- VOID(my_seek(fd, newlength, MY_SEEK_SET, MYF(MY_WME+MY_FAE)));
- swap(my_off_t, newlength, oldsize);
+ my_errno= errno;
+ goto err;
}
-#endif
- /* Full file with 0 until it's as big as requested */
- bfill(buff, IO_SIZE, filler);
- while (newlength-oldsize > IO_SIZE)
+ DBUG_RETURN(0);
+ }
+#elif defined(HAVE_CHSIZE)
+ {
+ if (chsize(fd, (off_t) newlength))
{
- if (my_write(fd,(byte*) buff,IO_SIZE,MYF(MY_NABP)))
- goto err;
- oldsize+= IO_SIZE;
- }
- if (my_write(fd,(byte*) buff,(uint) (newlength-oldsize),MYF(MY_NABP)))
+ my_errno=errno;
goto err;
+ }
DBUG_RETURN(0);
- err:
- if (MyFlags & MY_WME)
- my_error(EE_CANT_CHSIZE,MYF(ME_BELL+ME_WAITTANG),my_errno);
- DBUG_PRINT("error",("errno: %d",my_errno));
- DBUG_RETURN(1);
+ }
+#else
+ {
+ /*
+ Fill space between requested length and true length with 'filler'
+ We should never come here on any modern machine
+ */
+ VOID(my_seek(fd, newlength, MY_SEEK_SET, MYF(MY_WME+MY_FAE)));
+ swap(my_off_t, newlength, oldsize);
}
#endif
-} /* my_chsize */
+
+ /* Full file with 'filler' until it's as big as requested */
+ bfill(buff, IO_SIZE, filler);
+ while (newlength-oldsize > IO_SIZE)
+ {
+ if (my_write(fd,(byte*) buff,IO_SIZE,MYF(MY_NABP)))
+ goto err;
+ oldsize+= IO_SIZE;
+ }
+ if (my_write(fd,(byte*) buff,(uint) (newlength-oldsize),MYF(MY_NABP)))
+ goto err;
+ DBUG_RETURN(0);
+
+err:
+ DBUG_PRINT("error", ("errno: %d", errno));
+ if (MyFlags & MY_WME)
+ my_error(EE_CANT_CHSIZE, MYF(ME_BELL+ME_WAITTANG), my_errno);
+ DBUG_RETURN(1);
+} /* my_chsize */
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index cbbf876ac06..06e7b626bd7 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -525,8 +525,7 @@ static int setval(const struct my_option *opts, gptr *value, char *argument,
break;
case GET_STR_ALLOC:
if ((*((char**) result_pos)))
- my_free((*(char**) result_pos),
- MYF(MY_WME | MY_FAE));
+ my_free((*(char**) result_pos), MYF(MY_WME | MY_FAE));
if (!(*((char**) result_pos)= my_strdup(argument, MYF(MY_WME))))
return EXIT_OUT_OF_MEMORY;
break;
diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c
index 32528707480..f10a2210064 100644
--- a/mysys/my_pthread.c
+++ b/mysys/my_pthread.c
@@ -92,7 +92,7 @@ void *my_pthread_getspecific_imp(pthread_key_t key)
#ifdef __NETWARE__
/*
-don't kill the LibC Reaper thread or the main thread
+ Don't kill the LibC Reaper thread or the main thread
*/
#include <nks/thread.h>
#undef pthread_exit
@@ -105,8 +105,10 @@ void my_pthread_exit(void *status)
NXThreadGetContext(tid, &ctx);
NXContextGetName(ctx, name, PATH_MAX);
- // "MYSQLD.NLM's LibC Reaper" or "MYSQLD.NLM's main thread"
- // with a debug build of LibC the reaper can have different names
+ /*
+ "MYSQLD.NLM's LibC Reaper" or "MYSQLD.NLM's main thread"
+ with a debug build of LibC the reaper can have different names
+ */
if (!strindex(name, "\'s"))
{
pthread_exit(status);
@@ -114,8 +116,10 @@ void my_pthread_exit(void *status)
}
#endif
-/* Some functions for RTS threads, AIX, Siemens Unix and UnixWare 7
- (and DEC OSF/1 3.2 too) */
+/*
+ Some functions for RTS threads, AIX, Siemens Unix and UnixWare 7
+ (and DEC OSF/1 3.2 too)
+*/
int my_pthread_create_detached=1;