~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/default_modify.c

Merged in changes from Andrey.

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
 
  uint nr_newlines= 0, buffer_size;
 
66
  uint32_t nr_newlines= 0, buffer_size;
67
67
  bool in_section= false, opt_applied= 0;
68
 
  uint reserve_extended;
69
 
  uint new_opt_len;
 
68
  uint32_t reserve_extended;
 
69
  uint32_t new_opt_len;
70
70
  int reserve_occupied= 0;
71
71
 
72
72
  if (!(cnf_file= my_fopen(file_location, O_RDWR | O_BINARY, MYF(0))))
154
154
      }
155
155
 
156
156
      for (; nr_newlines; nr_newlines--)
157
 
        dst_ptr= stpcpy(dst_ptr, NEWLINE);
 
157
        dst_ptr= my_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= stpcpy(dst_ptr, linebuff);
 
161
        dst_ptr= my_stpcpy(dst_ptr, linebuff);
162
162
    }
163
163
    /* Look for a section */
164
164
    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= stpcpy(dst_ptr, NEWLINE);
 
200
      dst_ptr= my_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= stpcpy(dst_ptr, NEWLINE);
 
205
    dst_ptr= my_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, (uchar*) file_buffer, (size_t) (dst_ptr - file_buffer),
 
212
        my_fwrite(cnf_file, (unsigned char*) 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
 
  my_free(file_buffer, MYF(0));
 
219
  free(file_buffer);
220
220
  return(0);
221
221
 
222
222
err:
223
 
  my_free(file_buffer, MYF(0));
 
223
  free(file_buffer);
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= stpcpy(dst, option);
 
235
    dst= my_stpcpy(dst, option);
236
236
    if (*option_value)
237
237
    {
238
238
      *dst++= '=';
239
 
      dst= stpcpy(dst, option_value);
 
239
      dst= my_stpcpy(dst, option_value);
240
240
    }
241
241
    /* add a newline */
242
 
    dst= stpcpy(dst, NEWLINE);
 
242
    dst= my_stpcpy(dst, NEWLINE);
243
243
  }
244
244
  return dst;
245
245
}