1
1

* edit.h: Remove open, close, write, read and mkdir declaration.

* edit.c: Use mc_open, mc_close, mc_write, mc_read, mc_rename,
mc_chmod and mc_chown. Don't cast (char *) to (unsigned long)
in pointer arithmetics.
* editcmd.c: Likewise.
Этот коммит содержится в:
Andrew V. Samoilov 2002-05-13 16:53:51 +00:00
родитель baf5611b51
Коммит 0b08e1b69f
3 изменённых файлов: 52 добавлений и 49 удалений

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

@ -1,3 +1,11 @@
2002-05-13 Andrew V. Samoilov <kai@cmail.ru>
* edit.h: Remove open, close, write, read and mkdir declaration.
* edit.c: Use mc_open, mc_close, mc_write, mc_read, mc_rename,
mc_chmod and mc_chown. Don't cast (char *) to (unsigned long)
in pointer arithmetics.
* editcmd.c: Likewise.
2002-03-25 Andrew V. Samoilov <kai@cmail.ru> 2002-03-25 Andrew V. Samoilov <kai@cmail.ru>
* syntax.c (edit_read_syntax_file): Use system wide Syntax * syntax.c (edit_read_syntax_file): Use system wide Syntax

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

@ -182,7 +182,7 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
} }
if (filename) if (filename)
if ((file = open ((char *) filename, O_RDONLY)) == -1) { if ((file = mc_open (filename, O_RDONLY)) == -1) {
/* The file-name is printed after the ':' */ /* The file-name is printed after the ':' */
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0))); edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0)));
return 1; return 1;
@ -194,7 +194,7 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
edit->buffers2[buf2] = CMalloc (EDIT_BUF_SIZE); edit->buffers2[buf2] = CMalloc (EDIT_BUF_SIZE);
if (filename) { if (filename) {
read (file, (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE), edit->curs2 & M_EDIT_BUF_SIZE); mc_read (file, (char *) edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE), edit->curs2 & M_EDIT_BUF_SIZE);
} else { } else {
memcpy (edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE), text, edit->curs2 & M_EDIT_BUF_SIZE); memcpy (edit->buffers2[buf2] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE), text, edit->curs2 & M_EDIT_BUF_SIZE);
text += edit->curs2 & M_EDIT_BUF_SIZE; text += edit->curs2 & M_EDIT_BUF_SIZE;
@ -203,7 +203,7 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
for (buf = buf2 - 1; buf >= 0; buf--) { for (buf = buf2 - 1; buf >= 0; buf--) {
edit->buffers2[buf] = CMalloc (EDIT_BUF_SIZE); edit->buffers2[buf] = CMalloc (EDIT_BUF_SIZE);
if (filename) { if (filename) {
read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE); mc_read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE);
} else { } else {
memcpy (edit->buffers2[buf], text, EDIT_BUF_SIZE); memcpy (edit->buffers2[buf], text, EDIT_BUF_SIZE);
text += EDIT_BUF_SIZE; text += EDIT_BUF_SIZE;
@ -212,7 +212,7 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
edit->curs1 = 0; edit->curs1 = 0;
if (file != -1) if (file != -1)
close (file); mc_close (file);
return 0; return 0;
} }
@ -381,16 +381,16 @@ int edit_insert_file (WEdit * edit, const char *filename)
int i, file, blocklen; int i, file, blocklen;
long current = edit->curs1; long current = edit->curs1;
unsigned char *buf; unsigned char *buf;
if ((file = open ((char *) filename, O_RDONLY)) == -1) if ((file = mc_open (filename, O_RDONLY)) == -1)
return 0; return 0;
buf = malloc (TEMP_BUF_LEN); buf = malloc (TEMP_BUF_LEN);
while ((blocklen = read (file, (char *) buf, TEMP_BUF_LEN)) > 0) { while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0) {
for (i = 0; i < blocklen; i++) for (i = 0; i < blocklen; i++)
edit_insert (edit, buf[i]); edit_insert (edit, buf[i]);
} }
edit_cursor_move (edit, current - edit->curs1); edit_cursor_move (edit, current - edit->curs1);
free (buf); free (buf);
close (file); mc_close (file);
if (blocklen) if (blocklen)
return 0; return 0;
#endif #endif
@ -415,21 +415,18 @@ static int check_file_access (WEdit *edit, const char *filename, struct stat *st
} }
/* Open the file, create it if needed */ /* Open the file, create it if needed */
if ((file = open ((char *) filename, O_RDONLY)) < 0) { if ((file = mc_open (filename, O_RDONLY | O_CREAT, 0666)) < 0) {
close (creat ((char *) filename, 0666)); edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0)));
if ((file = open ((char *) filename, O_RDONLY)) < 0) { return 2;
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0)));
return 2;
}
} }
/* If the file has just been created, we don't have valid stat yet, so do it now */ /* If the file has just been created, we don't have valid stat yet, so do it now */
if (!stat_ok && mc_fstat (file, st) < 0) { if (!stat_ok && mc_fstat (file, st) < 0) {
close (file); mc_close (file);
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Cannot get size/permissions info on file: "), filename, " ", 0))); edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Cannot get size/permissions info on file: "), filename, " ", 0)));
return 1; return 1;
} }
close (file); mc_close (file);
if (st->st_size >= SIZE_LIMIT) { if (st->st_size >= SIZE_LIMIT) {
/* The file-name is printed after the ':' */ /* The file-name is printed after the ':' */
@ -472,9 +469,10 @@ int edit_open_file (WEdit * edit, const char *filename, const char *text, unsign
/* fills in the edit struct. returns 0 on fail. Pass edit as NULL for this */ /* fills in the edit struct. returns 0 on fail. Pass edit as NULL for this */
WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size) WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size)
{ {
char *f; const char *f;
int to_free = 0; int to_free = 0;
int use_filter = 0; int use_filter = 0;
if (!edit) { if (!edit) {
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
/* /*
@ -504,7 +502,7 @@ WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, co
memset (edit, 0, sizeof (WEdit)); memset (edit, 0, sizeof (WEdit));
to_free = 1; to_free = 1;
} }
memset (&(edit->from_here), 0, (unsigned long) &(edit->to_here) - (unsigned long) &(edit->from_here)); memset (&(edit->from_here), 0, &(edit->to_here) - &(edit->from_here));
edit->num_widget_lines = lines; edit->num_widget_lines = lines;
edit->num_widget_columns = columns; edit->num_widget_columns = columns;
edit->stat1.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; edit->stat1.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
@ -513,7 +511,7 @@ WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, co
edit->bracket = -1; edit->bracket = -1;
if (!dir) if (!dir)
dir = ""; dir = "";
f = (char *) filename; f = filename;
if (filename) { if (filename) {
f = catstrs (dir, filename, 0); f = catstrs (dir, filename, 0);
} }
@ -538,7 +536,7 @@ WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, co
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
if (filename) { if (filename) {
filename = catstrs (dir, filename, 0); filename = catstrs (dir, filename, 0);
edit_split_filename (edit, (char *) filename); edit_split_filename (edit, filename);
} else { } else {
edit->filename = (char *) strdup (""); edit->filename = (char *) strdup ("");
edit->dir = (char *) strdup (dir); edit->dir = (char *) strdup (dir);
@ -590,7 +588,7 @@ int edit_clean (WEdit * edit)
if (edit->dir) if (edit->dir)
free (edit->dir); free (edit->dir);
/* we don't want to clear the widget */ /* we don't want to clear the widget */
memset (&(edit->from_here), 0, (unsigned long) &(edit->to_here) - (unsigned long) &(edit->from_here)); memset (&(edit->from_here), 0, &(edit->to_here) - &(edit->from_here));
return 1; return 1;
} }
return 0; return 0;
@ -1675,7 +1673,7 @@ static unsigned long my_type_of (int c)
if (!q) if (!q)
return 0xFFFFFFFFUL; return 0xFFFFFFFFUL;
do { do {
for (x = 1, p = option_chars_move_whole_word; (unsigned long) p < (unsigned long) q; p++) for (x = 1, p = option_chars_move_whole_word; p < q; p++)
if (*p == '!') if (*p == '!')
x <<= 1; x <<= 1;
r |= x; r |= x;

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

@ -188,14 +188,14 @@ int edit_save_file (WEdit * edit, const char *filename)
if (!*filename) if (!*filename)
return 0; return 0;
if ((fd = open (filename, O_WRONLY)) == -1) { if ((fd = mc_open (filename, O_WRONLY)) == -1) {
/* /*
* The file does not exists yet, so no safe save or * The file does not exists yet, so no safe save or
* backup are necessary. * backup are necessary.
*/ */
this_save_mode = 0; this_save_mode = 0;
} else { } else {
close (fd); mc_close (fd);
this_save_mode = option_save_mode; this_save_mode = option_save_mode;
} }
@ -213,30 +213,27 @@ int edit_save_file (WEdit * edit, const char *filename)
g_free (saveprefix); g_free (saveprefix);
if (!savename) if (!savename)
return 0; return 0;
/* /* FIXME:
* FIXME: mc_mkstemps use pure open system call to create temporary file... * Close for now because mc_mkstemps use pure open system call
* This file handle must be close()d, but there is next line in edit.h: * to create temporary file and it needs to be reopened by
* #define close mc_close * VFS-aware mc_open() and MY_O_TEXT should be used.
* So this hack needed. */
*/
#undef close
close (fd); close (fd);
#define close mc_close
} else } else
savename = g_strdup (filename); savename = g_strdup (filename);
if ((fd = open (savename, O_CREAT | O_WRONLY | O_TRUNC | MY_O_TEXT, if ((fd = mc_open (savename, O_CREAT | O_WRONLY | O_TRUNC | MY_O_TEXT,
edit->stat1.st_mode)) == -1) edit->stat1.st_mode)) == -1)
goto error_save; goto error_save;
chmod (savename, edit->stat1.st_mode); mc_chmod (savename, edit->stat1.st_mode);
chown (savename, edit->stat1.st_uid, edit->stat1.st_gid); mc_chown (savename, edit->stat1.st_uid, edit->stat1.st_gid);
/* pipe save */ /* pipe save */
if ((p = (char *) edit_get_write_filter (savename, filename))) { if ((p = (char *) edit_get_write_filter (savename, filename))) {
FILE *file; FILE *file;
close (fd); mc_close (fd);
file = (FILE *) popen (p, "w"); file = (FILE *) popen (p, "w");
if (file) { if (file) {
@ -267,22 +264,22 @@ int edit_save_file (WEdit * edit, const char *filename)
buf = 0; buf = 0;
filelen = edit->last_byte; filelen = edit->last_byte;
while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) { while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) {
if (write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) { if (mc_write (fd, (char *) edit->buffers1[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) {
close (fd); mc_close (fd);
goto error_save; goto error_save;
} }
buf++; buf++;
} }
if (write (fd, (char *) edit->buffers1[buf], edit->curs1 & M_EDIT_BUF_SIZE) != (edit->curs1 & M_EDIT_BUF_SIZE)) { if (mc_write (fd, (char *) edit->buffers1[buf], edit->curs1 & M_EDIT_BUF_SIZE) != (edit->curs1 & M_EDIT_BUF_SIZE)) {
filelen = -1; filelen = -1;
} else if (edit->curs2) { } else if (edit->curs2) {
edit->curs2--; edit->curs2--;
buf = (edit->curs2 >> S_EDIT_BUF_SIZE); buf = (edit->curs2 >> S_EDIT_BUF_SIZE);
if (write (fd, (char *) edit->buffers2[buf] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1, 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) { if (mc_write (fd, (char *) edit->buffers2[buf] + EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1, 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) != 1 + (edit->curs2 & M_EDIT_BUF_SIZE)) {
filelen = -1; filelen = -1;
} else { } else {
while (--buf >= 0) { while (--buf >= 0) {
if (write (fd, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) { if (mc_write (fd, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) != EDIT_BUF_SIZE) {
filelen = -1; filelen = -1;
break; break;
} }
@ -290,7 +287,7 @@ int edit_save_file (WEdit * edit, const char *filename)
} }
edit->curs2++; edit->curs2++;
} }
if (close (fd)) if (mc_close (fd))
goto error_save; goto error_save;
#endif /* !CR_LF_TRANSLATION */ #endif /* !CR_LF_TRANSLATION */
} }
@ -298,10 +295,10 @@ int edit_save_file (WEdit * edit, const char *filename)
if (filelen != edit->last_byte) if (filelen != edit->last_byte)
goto error_save; goto error_save;
if (this_save_mode == 2) if (this_save_mode == 2)
if (rename (filename, catstrs (filename, option_backup_ext, 0)) == -1) if (mc_rename (filename, catstrs (filename, option_backup_ext, 0)) == -1)
goto error_save; goto error_save;
if (this_save_mode > 0) if (this_save_mode > 0)
if (rename (savename, filename) == -1) if (mc_rename (savename, filename) == -1)
goto error_save; goto error_save;
if (savename) if (savename)
g_free (savename); g_free (savename);
@ -419,8 +416,8 @@ int edit_save_as_cmd (WEdit * edit)
if (strcmp(catstrs (edit->dir, edit->filename, 0), exp)) { if (strcmp(catstrs (edit->dir, edit->filename, 0), exp)) {
int file; int file;
different_filename = 1; different_filename = 1;
if ((file = open ((char *) exp, O_RDONLY)) != -1) { /* the file exists */ if ((file = mc_open ((char *) exp, O_RDONLY)) != -1) { /* the file exists */
close (file); mc_close (file);
if (edit_query_dialog2 (_(" Warning "), if (edit_query_dialog2 (_(" Warning "),
_(" A file already exists with this name. "), _(" A file already exists with this name. "),
/* Push buttons to over-write the current file, or cancel the operation */ /* Push buttons to over-write the current file, or cancel the operation */
@ -1977,7 +1974,7 @@ int edit_save_block (WEdit * edit, const char *filename, long start, long finish
{ {
int len, file; int len, file;
if ((file = open ((char *) filename, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) if ((file = mc_open ((char *) filename, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
return 0; return 0;
if (column_highlighting) { if (column_highlighting) {
@ -1985,7 +1982,7 @@ int edit_save_block (WEdit * edit, const char *filename, long start, long finish
int r; int r;
p = block = edit_get_block (edit, start, finish, &len); p = block = edit_get_block (edit, start, finish, &len);
while (len) { while (len) {
r = write (file, p, len); r = mc_write (file, p, len);
if (r < 0) if (r < 0)
break; break;
p += r; p += r;
@ -2001,12 +1998,12 @@ int edit_save_block (WEdit * edit, const char *filename, long start, long finish
end = min (finish, start + TEMP_BUF_LEN); end = min (finish, start + TEMP_BUF_LEN);
for (; i < end; i++) for (; i < end; i++)
buf[i - start] = edit_get_byte (edit, i); buf[i - start] = edit_get_byte (edit, i);
len -= write (file, (char *) buf, end - start); len -= mc_write (file, (char *) buf, end - start);
start = end; start = end;
} }
free (buf); free (buf);
} }
close (file); mc_close (file);
if (len) if (len)
return 0; return 0;
return 1; return 1;