mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
manually merged 234_remove_g_string
This commit is contained in:
commit
9b9cab5874
@ -14,6 +14,7 @@
|
||||
fixed shell escaping issues in commandline completion engine
|
||||
* replaced buggy concat_dir_and_file() by mhl_str_dir_plus_file() (in mhl/string.h)
|
||||
* replaced g_snprintf() by snprintf()
|
||||
* replaced GString stuff by static buffers
|
||||
|
||||
2009-01-30 Enrico Weigelt, metux ITS <weigelt@metux.de>
|
||||
|
||||
|
41
edit/edit.c
41
edit/edit.c
@ -153,10 +153,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;
|
||||
}
|
||||
|
||||
@ -275,18 +274,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);
|
||||
mhl_mem_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);
|
||||
mhl_mem_free (p);
|
||||
return 0;
|
||||
}
|
||||
@ -316,7 +313,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);
|
||||
@ -331,8 +329,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 */
|
||||
@ -342,15 +339,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;
|
||||
}
|
||||
|
||||
@ -363,16 +358,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;
|
||||
|
@ -1236,14 +1236,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;
|
||||
@ -1262,7 +1264,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;
|
||||
}
|
||||
}
|
||||
|
@ -505,10 +505,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)) {
|
||||
@ -530,13 +534,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;
|
||||
}
|
||||
|
@ -590,7 +590,7 @@ putenv (char *string)
|
||||
size * sizeof (char *));
|
||||
new_environ[size] = (char *) string;
|
||||
new_environ[size + 1] = NULL;
|
||||
g_free ((void *) last_environ);
|
||||
mhl_mem_free ((void *) last_environ);
|
||||
last_environ = new_environ;
|
||||
__environ = new_environ;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user