1
1

replaced GString stuff by static buffers

Этот коммит содержится в:
Enrico Weigelt, metux IT service 2009-01-31 21:55:51 +01:00
родитель a1b47185c9
Коммит f235b1976e
4 изменённых файлов: 36 добавлений и 39 удалений

Просмотреть файл

@ -1,6 +1,7 @@
2009-01-31 Enrico Weigelt, metux ITS <weigelt@metux.de>
* 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 <weigelt@metux.de>

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -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;
}