diff --git a/ChangeLog b/ChangeLog index cc5b4dae0..abbe62524 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2009-01-31 Enrico Weigelt, metux ITS * replaced buggy concat_dir_and_file() by mhl_str_dir_plus_file() (in mhl/string.h) + * replaced GString stuff by static buffers 2009-01-30 Enrico Weigelt, metux ITS diff --git a/edit/edit.c b/edit/edit.c index bec84d78d..1f8d851dc 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -151,10 +151,9 @@ edit_load_file_fast (WEdit *edit, const char *filename) buf2 = edit->curs2 >> S_EDIT_BUF_SIZE; if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1) { - GString *errmsg = g_string_new(NULL); - g_string_sprintf(errmsg, _(" Cannot open %s for reading "), filename); - edit_error_dialog (_("Error"), get_sys_error (errmsg->str)); - g_string_free (errmsg, TRUE); + char errmsg[8192]; + snprintf(errmsg, sizeof(errmsg), _(" Cannot open %s for reading "), filename); + edit_error_dialog (_("Error"), get_sys_error (errmsg)); return 1; } @@ -273,18 +272,16 @@ edit_insert_file (WEdit *edit, const char *filename) edit_insert_stream (edit, f); edit_cursor_move (edit, current - edit->curs1); if (pclose (f) > 0) { - GString *errmsg = g_string_new (NULL); - g_string_sprintf (errmsg, _(" Error reading from pipe: %s "), p); - edit_error_dialog (_("Error"), errmsg->str); - g_string_free (errmsg, TRUE); + char errmsg[8192]; + snprintf(errmsg, sizeof(errmsg), _(" Error reading from pipe: %s "), p); + edit_error_dialog (_("Error"), errmsg); g_free (p); return 0; } } else { - GString *errmsg = g_string_new (NULL); - g_string_sprintf (errmsg, _(" Cannot open pipe for reading: %s "), p); - edit_error_dialog (_("Error"), errmsg->str); - g_string_free (errmsg, TRUE); + char errmsg[8192]; + snprintf(errmsg, sizeof(errmsg), _(" Cannot open pipe for reading: %s "), p); + edit_error_dialog (_("Error"), errmsg); g_free (p); return 0; } @@ -314,7 +311,8 @@ static int check_file_access (WEdit *edit, const char *filename, struct stat *st) { int file; - GString *errmsg = (GString *) 0; + char errmsg[8192]; + errmsg[0] = 0; /* Try opening an existing file */ file = mc_open (filename, O_NONBLOCK | O_RDONLY | O_BINARY, 0666); @@ -329,8 +327,7 @@ check_file_access (WEdit *edit, const char *filename, struct stat *st) O_NONBLOCK | O_RDONLY | O_BINARY | O_CREAT | O_EXCL, 0666); if (file < 0) { - g_string_sprintf (errmsg = g_string_new (NULL), - _(" Cannot open %s for reading "), filename); + snprintf (errmsg, sizeof(errmsg), _(" Cannot open %s for reading "), filename); goto cleanup; } else { /* New file, delete it if it's not modified or saved */ @@ -340,15 +337,13 @@ check_file_access (WEdit *edit, const char *filename, struct stat *st) /* Check what we have opened */ if (mc_fstat (file, st) < 0) { - g_string_sprintf (errmsg = g_string_new (NULL), - _(" Cannot get size/permissions for %s "), filename); + snprintf (errmsg, sizeof(errmsg), _(" Cannot get size/permissions for %s "), filename); goto cleanup; } /* We want to open regular files only */ if (!S_ISREG (st->st_mode)) { - g_string_sprintf (errmsg = g_string_new (NULL), - _(" %s is not a regular file "), filename); + snprintf (errmsg, sizeof(errmsg), _(" %s is not a regular file "), filename); goto cleanup; } @@ -361,16 +356,14 @@ check_file_access (WEdit *edit, const char *filename, struct stat *st) } if (st->st_size >= SIZE_LIMIT) { - g_string_sprintf (errmsg = g_string_new (NULL), - _(" File %s is too large "), filename); + snprintf (errmsg, sizeof(errmsg), _(" File %s is too large "), filename); goto cleanup; } cleanup: (void) mc_close (file); - if (errmsg) { - edit_error_dialog (_("Error"), errmsg->str); - g_string_free (errmsg, TRUE); + if (errmsg[0]) { + edit_error_dialog (_("Error"), errmsg); return 1; } return 0; diff --git a/edit/editcmd.c b/edit/editcmd.c index 9910f5c99..ec9a93146 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -1235,14 +1235,16 @@ edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos) 0, 0, 0, 0, 0}, NULL_QuickWidget}; - GString *label_text = g_string_new (_(" Replace with: ")); - if (*replace_text) { - size_t label_len; - label_len = label_text->len; - g_string_append (label_text, replace_text); - convert_to_display (label_text->str + label_len); + const char* label_nls = _(" Replace with: "); + char label_text[8192]; + if (*replace_text) + { + size_t label_len = strlen(label_nls); + snprintf(label_text, sizeof(label_text), "%s%s", label_nls, replace_text); + convert_to_display((&label_text)+label_len); } - quick_widgets[5].text = label_text->str; + + quick_widgets[5].text = label_text; { int retval; @@ -1261,7 +1263,6 @@ edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos) Quick_input.ypos = ypos; retval = quick_dialog (&Quick_input); - g_string_free (label_text, TRUE); return retval; } } diff --git a/edit/syntax.c b/edit/syntax.c index 2cfe97628..4aa62f879 100644 --- a/edit/syntax.c +++ b/edit/syntax.c @@ -506,10 +506,14 @@ void edit_get_syntax_color (WEdit * edit, long byte_index, int *color) */ static int read_one_line (char **line, FILE * f) { - GString *p = g_string_new (""); - int c, r = 0; + char buffer[8192]; + int index = 0, c, r = 0; + buffer[0] = 0; for (;;) { + if (index >= (sizeof(buffer)-1)) + break; + c = fgetc (f); if (c == EOF) { if (ferror (f)) { @@ -531,13 +535,11 @@ static int read_one_line (char **line, FILE * f) if (c == '\n') break; - g_string_append_c (p, c); + buffer[index] = c; + index++; } if (r != 0) { - *line = p->str; - g_string_free (p, FALSE); - } else { - g_string_free (p, TRUE); + *line = mhl_str_dup(buffer); } return r; }