~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default_modify.c

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
  struct stat file_stat;
64
64
  char linebuff[BUFF_SIZE], *src_ptr, *dst_ptr, *file_buffer;
65
65
  size_t opt_len= 0, optval_len= 0, sect_len;
66
 
  uint32_t nr_newlines= 0, buffer_size;
 
66
  uint nr_newlines= 0, buffer_size;
67
67
  bool in_section= false, opt_applied= 0;
68
 
  uint32_t reserve_extended;
69
 
  uint32_t new_opt_len;
 
68
  uint reserve_extended;
 
69
  uint new_opt_len;
70
70
  int reserve_occupied= 0;
71
71
 
72
 
  if (!(cnf_file= my_fopen(file_location, O_RDWR, MYF(0))))
 
72
  if (!(cnf_file= my_fopen(file_location, O_RDWR | O_BINARY, MYF(0))))
73
73
    return(2);
74
74
 
75
75
  if (fstat(fileno(cnf_file), &file_stat))
106
106
  for (dst_ptr= file_buffer; fgets(linebuff, BUFF_SIZE, cnf_file); )
107
107
  {
108
108
    /* Skip over whitespaces */
109
 
    for (src_ptr= linebuff; my_isspace(&my_charset_utf8_general_ci, *src_ptr);
 
109
    for (src_ptr= linebuff; my_isspace(&my_charset_latin1, *src_ptr);
110
110
         src_ptr++)
111
111
    {}
112
112
 
119
119
    /* correct the option (if requested) */
120
120
    if (option && in_section && !strncmp(src_ptr, option, opt_len) &&
121
121
        (*(src_ptr + opt_len) == '=' ||
122
 
         my_isspace(&my_charset_utf8_general_ci, *(src_ptr + opt_len)) ||
 
122
         my_isspace(&my_charset_latin1, *(src_ptr + opt_len)) ||
123
123
         *(src_ptr + opt_len) == '\0'))
124
124
    {
125
125
      char *old_src_ptr= src_ptr;
154
154
      }
155
155
 
156
156
      for (; nr_newlines; nr_newlines--)
157
 
        dst_ptr= my_stpcpy(dst_ptr, NEWLINE);
 
157
        dst_ptr= stpcpy(dst_ptr, NEWLINE);
158
158
 
159
159
      /* Skip the section if MY_REMOVE_SECTION was given */
160
160
      if (!in_section || remove_option != MY_REMOVE_SECTION)
161
 
        dst_ptr= my_stpcpy(dst_ptr, linebuff);
 
161
        dst_ptr= stpcpy(dst_ptr, linebuff);
162
162
    }
163
163
    /* Look for a section */
164
164
    if (*src_ptr == '[')
168
168
      {
169
169
        src_ptr+= sect_len;
170
170
        /* Skip over whitespaces. They are allowed after section name */
171
 
        for (; my_isspace(&my_charset_utf8_general_ci, *src_ptr); src_ptr++)
 
171
        for (; my_isspace(&my_charset_latin1, *src_ptr); src_ptr++)
172
172
        {}
173
173
 
174
174
        if (*src_ptr != ']')
197
197
  {
198
198
    /* New option still remains to apply at the end */
199
199
    if (!remove_option && *(dst_ptr - 1) != '\n')
200
 
      dst_ptr= my_stpcpy(dst_ptr, NEWLINE);
 
200
      dst_ptr= stpcpy(dst_ptr, NEWLINE);
201
201
    dst_ptr= add_option(dst_ptr, option_value, option, remove_option);
202
202
    opt_applied= 1;
203
203
  }
204
204
  for (; nr_newlines; nr_newlines--)
205
 
    dst_ptr= my_stpcpy(dst_ptr, NEWLINE);
 
205
    dst_ptr= stpcpy(dst_ptr, NEWLINE);
206
206
 
207
207
  if (opt_applied)
208
208
  {
209
209
    /* Don't write the file if there are no changes to be made */
210
210
    if (ftruncate(fileno(cnf_file), (my_off_t) (dst_ptr - file_buffer)) ||
211
211
        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),
 
212
        my_fwrite(cnf_file, (uchar*) file_buffer, (size_t) (dst_ptr - file_buffer),
213
213
                  MYF(MY_NABP)))
214
214
      goto err;
215
215
  }
216
216
  if (my_fclose(cnf_file, MYF(MY_WME)))
217
217
    return(1);
218
218
 
219
 
  free(file_buffer);
 
219
  my_free(file_buffer, MYF(0));
220
220
  return(0);
221
221
 
222
222
err:
223
 
  free(file_buffer);
 
223
  my_free(file_buffer, MYF(0));
224
224
malloc_err:
225
225
  my_fclose(cnf_file, MYF(0));
226
226
  return(1); /* out of resources */
232
232
{
233
233
  if (!remove_option)
234
234
  {
235
 
    dst= my_stpcpy(dst, option);
 
235
    dst= stpcpy(dst, option);
236
236
    if (*option_value)
237
237
    {
238
238
      *dst++= '=';
239
 
      dst= my_stpcpy(dst, option_value);
 
239
      dst= stpcpy(dst, option_value);
240
240
    }
241
241
    /* add a newline */
242
 
    dst= my_stpcpy(dst, NEWLINE);
 
242
    dst= stpcpy(dst, NEWLINE);
243
243
  }
244
244
  return dst;
245
245
}