* 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.
This commit is contained in:
Andrew V. Samoilov 2002-05-13 16:53:51 +00:00
parent baf5611b51
commit 0b08e1b69f
3 changed files with 52 additions and 49 deletions

View File

@ -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>
* syntax.c (edit_read_syntax_file): Use system wide Syntax

View File

@ -182,7 +182,7 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
}
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 ':' */
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0)));
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);
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 {
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;
@ -203,7 +203,7 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
for (buf = buf2 - 1; buf >= 0; buf--) {
edit->buffers2[buf] = CMalloc (EDIT_BUF_SIZE);
if (filename) {
read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE);
mc_read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE);
} else {
memcpy (edit->buffers2[buf], 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;
if (file != -1)
close (file);
mc_close (file);
return 0;
}
@ -381,16 +381,16 @@ int edit_insert_file (WEdit * edit, const char *filename)
int i, file, blocklen;
long current = edit->curs1;
unsigned char *buf;
if ((file = open ((char *) filename, O_RDONLY)) == -1)
if ((file = mc_open (filename, O_RDONLY)) == -1)
return 0;
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++)
edit_insert (edit, buf[i]);
}
edit_cursor_move (edit, current - edit->curs1);
free (buf);
close (file);
mc_close (file);
if (blocklen)
return 0;
#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 */
if ((file = open ((char *) filename, O_RDONLY)) < 0) {
close (creat ((char *) filename, 0666));
if ((file = open ((char *) filename, O_RDONLY)) < 0) {
edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0)));
return 2;
}
if ((file = mc_open (filename, O_RDONLY | O_CREAT, 0666)) < 0) {
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 (!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)));
return 1;
}
close (file);
mc_close (file);
if (st->st_size >= SIZE_LIMIT) {
/* 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 */
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 use_filter = 0;
if (!edit) {
#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));
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_columns = columns;
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;
if (!dir)
dir = "";
f = (char *) filename;
f = filename;
if (filename) {
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;
if (filename) {
filename = catstrs (dir, filename, 0);
edit_split_filename (edit, (char *) filename);
edit_split_filename (edit, filename);
} else {
edit->filename = (char *) strdup ("");
edit->dir = (char *) strdup (dir);
@ -590,7 +588,7 @@ int edit_clean (WEdit * edit)
if (edit->dir)
free (edit->dir);
/* 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 0;
@ -1675,7 +1673,7 @@ static unsigned long my_type_of (int c)
if (!q)
return 0xFFFFFFFFUL;
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 == '!')
x <<= 1;
r |= x;

View File

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