(edit_buffer_read_file): refactoring: return number of read bytes.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
fc8044e178
Коммит
e6ff98d239
@ -162,7 +162,7 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = edit_buffer_read_file (&edit->buffer, file, edit->last_byte);
|
ret = (edit_buffer_read_file (&edit->buffer, file, edit->last_byte) == edit->last_byte);
|
||||||
if (ret)
|
if (ret)
|
||||||
edit->total_lines = edit_count_lines (edit, 0, edit->last_byte);
|
edit->total_lines = edit_count_lines (edit, 0, edit->last_byte);
|
||||||
else
|
else
|
||||||
|
@ -307,12 +307,13 @@ edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char
|
|||||||
* @param fd file descriptor
|
* @param fd file descriptor
|
||||||
* @param size file size
|
* @param size file size
|
||||||
*
|
*
|
||||||
* @return TRUE if file was readed successfully, FALSE otherwise
|
* @return number of read bytes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
gboolean
|
off_t
|
||||||
edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size)
|
edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size)
|
||||||
{
|
{
|
||||||
|
off_t ret;
|
||||||
off_t i;
|
off_t i;
|
||||||
off_t data_size;
|
off_t data_size;
|
||||||
|
|
||||||
@ -324,21 +325,27 @@ edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size)
|
|||||||
|
|
||||||
/* fill last part of buffers2 */
|
/* fill last part of buffers2 */
|
||||||
data_size = buf->curs2 & M_EDIT_BUF_SIZE;
|
data_size = buf->curs2 & M_EDIT_BUF_SIZE;
|
||||||
if (mc_read (fd, (char *) buf->buffers2[i] + EDIT_BUF_SIZE - data_size, data_size) < 0)
|
ret = mc_read (fd, (char *) buf->buffers2[i] + EDIT_BUF_SIZE - data_size, data_size);
|
||||||
return FALSE;
|
if (ret < 0 || ret != data_size)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/* fullfill other parts of buffers2 from end to begin */
|
/* fullfill other parts of buffers2 from end to begin */
|
||||||
data_size = EDIT_BUF_SIZE;
|
data_size = EDIT_BUF_SIZE;
|
||||||
for (--i; i >= 0; i--)
|
for (--i; i >= 0; i--)
|
||||||
{
|
{
|
||||||
|
off_t sz;
|
||||||
|
|
||||||
/* edit->buffers2[0] is already allocated */
|
/* edit->buffers2[0] is already allocated */
|
||||||
if (buf->buffers2[i] == NULL)
|
if (buf->buffers2[i] == NULL)
|
||||||
buf->buffers2[i] = g_malloc0 (data_size);
|
buf->buffers2[i] = g_malloc0 (data_size);
|
||||||
if (mc_read (fd, (char *) buf->buffers2[i], data_size) < 0)
|
sz = mc_read (fd, (char *) buf->buffers2[i], data_size);
|
||||||
return FALSE;
|
if (sz >= 0)
|
||||||
|
ret += sz;
|
||||||
|
if (sz != data_size)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -58,7 +58,7 @@ int edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_
|
|||||||
int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width);
|
int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gboolean edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size);
|
off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size);
|
||||||
|
|
||||||
/*** inline functions ****************************************************************************/
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user