~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default_modify.c

  • Committer: Brian Aker
  • Date: 2008-07-18 22:05:16 UTC
  • Revision ID: brian@tangent.org-20080718220516-dzyjle0iqqjssphx
Dead debug code removal (and a compatible "never used") bit in the
optimizer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
 
16
#include "my_global.h"
16
17
#include "mysys_priv.h"
17
 
#include <mystrings/m_string.h>
 
18
#include "m_string.h"
18
19
#include <my_dir.h>
19
20
 
20
21
#define BUFF_SIZE 1024
63
64
  struct stat file_stat;
64
65
  char linebuff[BUFF_SIZE], *src_ptr, *dst_ptr, *file_buffer;
65
66
  size_t opt_len= 0, optval_len= 0, sect_len;
66
 
  uint32_t nr_newlines= 0, buffer_size;
 
67
  uint nr_newlines= 0, buffer_size;
67
68
  bool in_section= false, opt_applied= 0;
68
 
  uint32_t reserve_extended;
69
 
  uint32_t new_opt_len;
 
69
  uint reserve_extended;
 
70
  uint new_opt_len;
70
71
  int reserve_occupied= 0;
71
72
 
72
73
  if (!(cnf_file= my_fopen(file_location, O_RDWR | O_BINARY, MYF(0))))
106
107
  for (dst_ptr= file_buffer; fgets(linebuff, BUFF_SIZE, cnf_file); )
107
108
  {
108
109
    /* Skip over whitespaces */
109
 
    for (src_ptr= linebuff; my_isspace(&my_charset_utf8_general_ci, *src_ptr);
 
110
    for (src_ptr= linebuff; my_isspace(&my_charset_latin1, *src_ptr);
110
111
         src_ptr++)
111
112
    {}
112
113
 
119
120
    /* correct the option (if requested) */
120
121
    if (option && in_section && !strncmp(src_ptr, option, opt_len) &&
121
122
        (*(src_ptr + opt_len) == '=' ||
122
 
         my_isspace(&my_charset_utf8_general_ci, *(src_ptr + opt_len)) ||
 
123
         my_isspace(&my_charset_latin1, *(src_ptr + opt_len)) ||
123
124
         *(src_ptr + opt_len) == '\0'))
124
125
    {
125
126
      char *old_src_ptr= src_ptr;
126
 
      src_ptr= strchr(src_ptr+ opt_len, '\0');        /* Find the end of the line */
 
127
      src_ptr= strend(src_ptr+ opt_len);        /* Find the end of the line */
127
128
 
128
129
      /* could be negative */
129
130
      reserve_occupied+= (int) new_opt_len - (int) (src_ptr - old_src_ptr);
154
155
      }
155
156
 
156
157
      for (; nr_newlines; nr_newlines--)
157
 
        dst_ptr= my_stpcpy(dst_ptr, NEWLINE);
 
158
        dst_ptr= strmov(dst_ptr, NEWLINE);
158
159
 
159
160
      /* Skip the section if MY_REMOVE_SECTION was given */
160
161
      if (!in_section || remove_option != MY_REMOVE_SECTION)
161
 
        dst_ptr= my_stpcpy(dst_ptr, linebuff);
 
162
        dst_ptr= strmov(dst_ptr, linebuff);
162
163
    }
163
164
    /* Look for a section */
164
165
    if (*src_ptr == '[')
168
169
      {
169
170
        src_ptr+= sect_len;
170
171
        /* Skip over whitespaces. They are allowed after section name */
171
 
        for (; my_isspace(&my_charset_utf8_general_ci, *src_ptr); src_ptr++)
 
172
        for (; my_isspace(&my_charset_latin1, *src_ptr); src_ptr++)
172
173
        {}
173
174
 
174
175
        if (*src_ptr != ']')
197
198
  {
198
199
    /* New option still remains to apply at the end */
199
200
    if (!remove_option && *(dst_ptr - 1) != '\n')
200
 
      dst_ptr= my_stpcpy(dst_ptr, NEWLINE);
 
201
      dst_ptr= strmov(dst_ptr, NEWLINE);
201
202
    dst_ptr= add_option(dst_ptr, option_value, option, remove_option);
202
203
    opt_applied= 1;
203
204
  }
204
205
  for (; nr_newlines; nr_newlines--)
205
 
    dst_ptr= my_stpcpy(dst_ptr, NEWLINE);
 
206
    dst_ptr= strmov(dst_ptr, NEWLINE);
206
207
 
207
208
  if (opt_applied)
208
209
  {
209
210
    /* Don't write the file if there are no changes to be made */
210
211
    if (ftruncate(fileno(cnf_file), (my_off_t) (dst_ptr - file_buffer)) ||
211
212
        my_fseek(cnf_file, 0, MY_SEEK_SET, MYF(0)) ||
212
 
        my_fwrite(cnf_file, (unsigned char*) file_buffer, (size_t) (dst_ptr - file_buffer),
 
213
        my_fwrite(cnf_file, (uchar*) file_buffer, (size_t) (dst_ptr - file_buffer),
213
214
                  MYF(MY_NABP)))
214
215
      goto err;
215
216
  }
216
217
  if (my_fclose(cnf_file, MYF(MY_WME)))
217
218
    return(1);
218
219
 
219
 
  free(file_buffer);
 
220
  my_free(file_buffer, MYF(0));
220
221
  return(0);
221
222
 
222
223
err:
223
 
  free(file_buffer);
 
224
  my_free(file_buffer, MYF(0));
224
225
malloc_err:
225
226
  my_fclose(cnf_file, MYF(0));
226
227
  return(1); /* out of resources */
232
233
{
233
234
  if (!remove_option)
234
235
  {
235
 
    dst= my_stpcpy(dst, option);
 
236
    dst= strmov(dst, option);
236
237
    if (*option_value)
237
238
    {
238
239
      *dst++= '=';
239
 
      dst= my_stpcpy(dst, option_value);
 
240
      dst= strmov(dst, option_value);
240
241
    }
241
242
    /* add a newline */
242
 
    dst= my_stpcpy(dst, NEWLINE);
 
243
    dst= strmov(dst, NEWLINE);
243
244
  }
244
245
  return dst;
245
246
}