2005-06-22 03:40:06 +02:00
|
|
|
/* Copyright (C) 2005 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2005-06-22 03:40:06 +02:00
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
#include "my_global.h"
|
|
|
|
#include "mysys_priv.h"
|
|
|
|
#include "m_string.h"
|
|
|
|
#include <my_dir.h>
|
|
|
|
|
|
|
|
#define BUFF_SIZE 1024
|
2005-07-18 14:33:18 +02:00
|
|
|
#define RESERVE 1024 /* Extend buffer with this extent */
|
2005-06-22 03:40:06 +02:00
|
|
|
|
2009-09-11 22:26:35 +02:00
|
|
|
#ifdef _WIN32
|
2005-06-22 03:40:06 +02:00
|
|
|
#define NEWLINE "\r\n"
|
|
|
|
#define NEWLINE_LEN 2
|
|
|
|
#else
|
|
|
|
#define NEWLINE "\n"
|
|
|
|
#define NEWLINE_LEN 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static char *add_option(char *dst, const char *option_value,
|
|
|
|
const char *option, int remove_option);
|
|
|
|
|
|
|
|
|
2005-05-18 19:10:17 +02:00
|
|
|
/*
|
|
|
|
Add/remove option to the option file section.
|
|
|
|
|
|
|
|
SYNOPSYS
|
|
|
|
modify_defaults_file()
|
|
|
|
file_location The location of configuration file to edit
|
2006-05-18 16:57:50 +02:00
|
|
|
option The name of the option to look for (can be NULL)
|
|
|
|
option value The value of the option we would like to set (can be NULL)
|
|
|
|
section_name The name of the section (must be NOT NULL)
|
|
|
|
remove_option This defines what we want to remove:
|
|
|
|
- MY_REMOVE_NONE -- nothing to remove;
|
|
|
|
- MY_REMOVE_OPTION -- remove the specified option;
|
|
|
|
- MY_REMOVE_SECTION -- remove the specified section;
|
2005-05-18 19:10:17 +02:00
|
|
|
IMPLEMENTATION
|
|
|
|
We open the option file first, then read the file line-by-line,
|
|
|
|
looking for the section we need. At the same time we put these lines
|
|
|
|
into a buffer. Then we look for the option within this section and
|
|
|
|
change/remove it. In the end we get a buffer with modified version of the
|
|
|
|
file. Then we write it to the file, truncate it if needed and close it.
|
2005-06-22 03:40:06 +02:00
|
|
|
Note that there is a small time gap, when the file is incomplete,
|
|
|
|
and this theoretically might introduce a problem.
|
2005-05-18 19:10:17 +02:00
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 - ok
|
|
|
|
1 - some error has occured. Probably due to the lack of resourses
|
|
|
|
2 - cannot open the file
|
|
|
|
*/
|
|
|
|
|
2005-05-19 12:02:12 +02:00
|
|
|
int modify_defaults_file(const char *file_location, const char *option,
|
|
|
|
const char *option_value,
|
|
|
|
const char *section_name, int remove_option)
|
2005-05-18 19:10:17 +02:00
|
|
|
{
|
|
|
|
FILE *cnf_file;
|
2005-05-21 23:23:39 +02:00
|
|
|
MY_STAT file_stat;
|
2005-06-09 20:50:22 +02:00
|
|
|
char linebuff[BUFF_SIZE], *src_ptr, *dst_ptr, *file_buffer;
|
2009-02-13 17:41:47 +01:00
|
|
|
size_t opt_len= 0, optval_len= 0, sect_len, new_opt_len, reserve_extended;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
uint nr_newlines= 0, buffer_size;
|
2005-06-09 20:50:22 +02:00
|
|
|
my_bool in_section= FALSE, opt_applied= 0;
|
2005-06-29 00:24:31 +02:00
|
|
|
int reserve_occupied= 0;
|
2005-05-18 19:10:17 +02:00
|
|
|
DBUG_ENTER("modify_defaults_file");
|
|
|
|
|
|
|
|
if (!(cnf_file= my_fopen(file_location, O_RDWR | O_BINARY, MYF(0))))
|
|
|
|
DBUG_RETURN(2);
|
|
|
|
|
|
|
|
/* my_fstat doesn't use the flag parameter */
|
2009-09-11 22:26:35 +02:00
|
|
|
if (my_fstat(my_fileno(cnf_file), &file_stat, MYF(0)))
|
2005-06-29 11:27:27 +02:00
|
|
|
goto malloc_err;
|
2005-05-18 19:10:17 +02:00
|
|
|
|
2006-05-18 16:57:50 +02:00
|
|
|
if (option && option_value)
|
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
opt_len= strlen(option);
|
|
|
|
optval_len= strlen(option_value);
|
2006-05-18 16:57:50 +02:00
|
|
|
}
|
2005-06-09 20:50:22 +02:00
|
|
|
|
2005-06-29 11:27:27 +02:00
|
|
|
new_opt_len= opt_len + 1 + optval_len + NEWLINE_LEN;
|
|
|
|
|
2005-06-23 16:13:58 +02:00
|
|
|
/* calculate the size of the buffer we need */
|
2005-07-18 14:33:18 +02:00
|
|
|
reserve_extended= (opt_len +
|
|
|
|
1 + /* For '=' char */
|
|
|
|
optval_len + /* Option value len */
|
|
|
|
NEWLINE_LEN + /* Space for newline */
|
|
|
|
RESERVE); /* Some additional space */
|
|
|
|
|
|
|
|
buffer_size= (file_stat.st_size +
|
|
|
|
1); /* The ending zero */
|
2005-06-23 16:13:58 +02:00
|
|
|
|
2005-05-18 19:10:17 +02:00
|
|
|
/*
|
|
|
|
Reserve space to read the contents of the file and some more
|
|
|
|
for the option we want to add.
|
|
|
|
*/
|
2005-07-18 14:33:18 +02:00
|
|
|
if (!(file_buffer= (char*) my_malloc(buffer_size + reserve_extended,
|
|
|
|
MYF(MY_WME))))
|
2005-05-18 19:10:17 +02:00
|
|
|
goto malloc_err;
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
sect_len= strlen(section_name);
|
2005-06-09 20:50:22 +02:00
|
|
|
|
|
|
|
for (dst_ptr= file_buffer; fgets(linebuff, BUFF_SIZE, cnf_file); )
|
2005-05-18 19:10:17 +02:00
|
|
|
{
|
|
|
|
/* Skip over whitespaces */
|
|
|
|
for (src_ptr= linebuff; my_isspace(&my_charset_latin1, *src_ptr);
|
|
|
|
src_ptr++)
|
|
|
|
{}
|
|
|
|
|
2005-06-09 20:50:22 +02:00
|
|
|
if (!*src_ptr) /* Empty line */
|
|
|
|
{
|
|
|
|
nr_newlines++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-05-18 16:57:50 +02:00
|
|
|
/* correct the option (if requested) */
|
|
|
|
if (option && in_section && !strncmp(src_ptr, option, opt_len) &&
|
2005-06-22 03:40:06 +02:00
|
|
|
(*(src_ptr + opt_len) == '=' ||
|
|
|
|
my_isspace(&my_charset_latin1, *(src_ptr + opt_len)) ||
|
|
|
|
*(src_ptr + opt_len) == '\0'))
|
2005-05-18 19:10:17 +02:00
|
|
|
{
|
2005-07-18 14:33:18 +02:00
|
|
|
char *old_src_ptr= src_ptr;
|
|
|
|
src_ptr= strend(src_ptr+ opt_len); /* Find the end of the line */
|
|
|
|
|
|
|
|
/* could be negative */
|
|
|
|
reserve_occupied+= (int) new_opt_len - (int) (src_ptr - old_src_ptr);
|
|
|
|
if (reserve_occupied >= (int) reserve_extended)
|
2005-06-23 16:13:58 +02:00
|
|
|
{
|
2005-07-18 14:33:18 +02:00
|
|
|
reserve_extended= (uint) reserve_occupied + RESERVE;
|
|
|
|
if (!(file_buffer= (char*) my_realloc(file_buffer, buffer_size +
|
|
|
|
reserve_extended,
|
|
|
|
MYF(MY_WME|MY_FREE_ON_ERROR))))
|
|
|
|
goto malloc_err;
|
2005-06-23 16:13:58 +02:00
|
|
|
}
|
2005-07-18 14:33:18 +02:00
|
|
|
opt_applied= 1;
|
2005-06-09 20:50:22 +02:00
|
|
|
dst_ptr= add_option(dst_ptr, option_value, option, remove_option);
|
2005-05-18 19:10:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-18 16:57:50 +02:00
|
|
|
/*
|
|
|
|
If we are going to the new group and have an option to apply, do
|
|
|
|
it now. If we are removing a single option or the whole section
|
|
|
|
this will only trigger opt_applied flag.
|
|
|
|
*/
|
|
|
|
|
2005-06-09 20:50:22 +02:00
|
|
|
if (in_section && !opt_applied && *src_ptr == '[')
|
2005-05-18 19:10:17 +02:00
|
|
|
{
|
2005-06-22 03:40:06 +02:00
|
|
|
dst_ptr= add_option(dst_ptr, option_value, option, remove_option);
|
|
|
|
opt_applied= 1; /* set the flag to do write() later */
|
2005-07-18 14:33:18 +02:00
|
|
|
reserve_occupied= new_opt_len+ opt_len + 1 + NEWLINE_LEN;
|
2005-05-18 19:10:17 +02:00
|
|
|
}
|
2005-06-22 03:40:06 +02:00
|
|
|
|
2005-06-09 20:50:22 +02:00
|
|
|
for (; nr_newlines; nr_newlines--)
|
2005-06-22 03:40:06 +02:00
|
|
|
dst_ptr= strmov(dst_ptr, NEWLINE);
|
2006-05-18 16:57:50 +02:00
|
|
|
|
|
|
|
/* Skip the section if MY_REMOVE_SECTION was given */
|
|
|
|
if (!in_section || remove_option != MY_REMOVE_SECTION)
|
|
|
|
dst_ptr= strmov(dst_ptr, linebuff);
|
2005-05-18 19:10:17 +02:00
|
|
|
}
|
|
|
|
/* Look for a section */
|
|
|
|
if (*src_ptr == '[')
|
|
|
|
{
|
|
|
|
/* Copy the line to the buffer */
|
|
|
|
if (!strncmp(++src_ptr, section_name, sect_len))
|
|
|
|
{
|
2005-06-22 03:40:06 +02:00
|
|
|
src_ptr+= sect_len;
|
|
|
|
/* Skip over whitespaces. They are allowed after section name */
|
|
|
|
for (; my_isspace(&my_charset_latin1, *src_ptr); src_ptr++)
|
|
|
|
{}
|
2005-05-18 19:10:17 +02:00
|
|
|
|
2005-06-22 03:40:06 +02:00
|
|
|
if (*src_ptr != ']')
|
2006-05-18 16:57:50 +02:00
|
|
|
{
|
|
|
|
in_section= FALSE;
|
2005-06-22 03:40:06 +02:00
|
|
|
continue; /* Missing closing parenthesis. Assume this was no group */
|
2006-05-18 16:57:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (remove_option == MY_REMOVE_SECTION)
|
|
|
|
dst_ptr= dst_ptr - strlen(linebuff);
|
|
|
|
|
2005-05-18 19:10:17 +02:00
|
|
|
in_section= TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
in_section= FALSE; /* mark that this section is of no interest to us */
|
|
|
|
}
|
|
|
|
}
|
2006-05-18 16:57:50 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
File ended. Apply an option or set opt_applied flag (in case of
|
|
|
|
MY_REMOVE_SECTION) so that the changes are saved. Do not do anything
|
|
|
|
if we are removing non-existent option.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!opt_applied && in_section && (remove_option != MY_REMOVE_OPTION))
|
2005-05-18 19:10:17 +02:00
|
|
|
{
|
2005-06-09 20:50:22 +02:00
|
|
|
/* New option still remains to apply at the end */
|
2006-05-18 16:57:50 +02:00
|
|
|
if (!remove_option && *(dst_ptr - 1) != '\n')
|
2005-06-09 20:50:22 +02:00
|
|
|
dst_ptr= strmov(dst_ptr, NEWLINE);
|
|
|
|
dst_ptr= add_option(dst_ptr, option_value, option, remove_option);
|
|
|
|
opt_applied= 1;
|
2005-05-18 19:10:17 +02:00
|
|
|
}
|
2005-06-09 20:50:22 +02:00
|
|
|
for (; nr_newlines; nr_newlines--)
|
|
|
|
dst_ptr= strmov(dst_ptr, NEWLINE);
|
2005-05-18 19:10:17 +02:00
|
|
|
|
2005-06-09 20:50:22 +02:00
|
|
|
if (opt_applied)
|
|
|
|
{
|
|
|
|
/* Don't write the file if there are no changes to be made */
|
2009-09-11 22:26:35 +02:00
|
|
|
if (my_chsize(my_fileno(cnf_file), (my_off_t) (dst_ptr - file_buffer), 0,
|
2005-06-22 03:40:06 +02:00
|
|
|
MYF(MY_WME)) ||
|
|
|
|
my_fseek(cnf_file, 0, MY_SEEK_SET, MYF(0)) ||
|
2007-07-30 10:33:50 +02:00
|
|
|
my_fwrite(cnf_file, (uchar*) file_buffer, (size_t) (dst_ptr - file_buffer),
|
2005-06-22 03:40:06 +02:00
|
|
|
MYF(MY_NABP)))
|
2005-06-09 20:50:22 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (my_fclose(cnf_file, MYF(MY_WME)))
|
2006-01-03 17:54:54 +01:00
|
|
|
DBUG_RETURN(1);
|
2005-05-18 19:10:17 +02:00
|
|
|
|
|
|
|
my_free(file_buffer, MYF(0));
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
err:
|
|
|
|
my_free(file_buffer, MYF(0));
|
|
|
|
malloc_err:
|
|
|
|
my_fclose(cnf_file, MYF(0));
|
|
|
|
DBUG_RETURN(1); /* out of resources */
|
|
|
|
}
|
2005-06-09 20:50:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
static char *add_option(char *dst, const char *option_value,
|
|
|
|
const char *option, int remove_option)
|
|
|
|
{
|
|
|
|
if (!remove_option)
|
|
|
|
{
|
|
|
|
dst= strmov(dst, option);
|
|
|
|
if (*option_value)
|
|
|
|
{
|
|
|
|
*dst++= '=';
|
|
|
|
dst= strmov(dst, option_value);
|
|
|
|
}
|
|
|
|
/* add a newline */
|
|
|
|
dst= strmov(dst, NEWLINE);
|
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|