Commit 9d669888 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

file: use vlc_read_i11e() and simplify

parent d71bd09f
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
#endif #endif
#include <vlc_fs.h> #include <vlc_fs.h>
#include <vlc_url.h> #include <vlc_url.h>
#include <vlc_interrupt.h>
struct access_sys_t struct access_sys_t
{ {
...@@ -190,14 +191,8 @@ int FileOpen( vlc_object_t *p_this ) ...@@ -190,14 +191,8 @@ int FileOpen( vlc_object_t *p_this )
} }
#if O_NONBLOCK #if O_NONBLOCK
int flags = fcntl (fd, F_GETFL); /* Force blocking mode back */
if (S_ISFIFO (st.st_mode) || S_ISSOCK (st.st_mode)) fcntl (fd, fcntl (fd, F_GETFL) & ~O_NONBLOCK);
/* Force non-blocking mode where applicable (fd://) */
flags |= O_NONBLOCK;
else
/* Force blocking mode when not useful or not specified */
flags &= ~O_NONBLOCK;
fcntl (fd, F_SETFL, flags);
#endif #endif
/* Directories can be opened and read from, but only readdir() knows /* Directories can be opened and read from, but only readdir() knows
...@@ -282,42 +277,23 @@ void FileClose (vlc_object_t * p_this) ...@@ -282,42 +277,23 @@ void FileClose (vlc_object_t * p_this)
} }
#include <vlc_network.h>
/** /**
* Reads from a regular file. * Reads from a regular file.
*/ */
static ssize_t FileRead (access_t *p_access, uint8_t *p_buffer, size_t i_len) static ssize_t FileRead (access_t *p_access, uint8_t *p_buffer, size_t i_len)
{ {
access_sys_t *p_sys = p_access->p_sys; ssize_t val = StreamRead (p_access, p_buffer, i_len);
int fd = p_sys->fd;
ssize_t val = read (fd, p_buffer, i_len);
if (val < 0)
{
switch (errno)
{
case EINTR:
case EAGAIN:
return -1;
}
msg_Err (p_access, "read error: %s", vlc_strerror_c(errno)); access_sys_t *p_sys = p_access->p_sys;
dialog_Fatal (p_access, _("File reading failed"),
_("VLC could not read the file (%s)."),
vlc_strerror(errno));
val = 0;
}
p_access->info.i_pos += val;
p_access->info.b_eof = !val;
if (p_access->info.i_pos >= p_sys->size) if (p_access->info.i_pos >= p_sys->size)
{ {
struct stat st; struct stat st;
if (fstat (fd, &st) == 0) if (fstat (p_sys->fd, &st) == 0)
p_sys->size = st.st_size; p_sys->size = st.st_size;
} }
return val; return val;
} }
...@@ -343,12 +319,7 @@ static ssize_t StreamRead (access_t *p_access, uint8_t *p_buffer, size_t i_len) ...@@ -343,12 +319,7 @@ static ssize_t StreamRead (access_t *p_access, uint8_t *p_buffer, size_t i_len)
access_sys_t *p_sys = p_access->p_sys; access_sys_t *p_sys = p_access->p_sys;
int fd = p_sys->fd; int fd = p_sys->fd;
#if !defined (_WIN32) && !defined (__OS2__) ssize_t val = vlc_read_i11e (fd, p_buffer, i_len);
ssize_t val = net_Read (p_access, fd, p_buffer, i_len, false);
#else
ssize_t val = read (fd, p_buffer, i_len);
#endif
if (val < 0) if (val < 0)
{ {
switch (errno) switch (errno)
...@@ -357,7 +328,11 @@ static ssize_t StreamRead (access_t *p_access, uint8_t *p_buffer, size_t i_len) ...@@ -357,7 +328,11 @@ static ssize_t StreamRead (access_t *p_access, uint8_t *p_buffer, size_t i_len)
case EAGAIN: case EAGAIN:
return -1; return -1;
} }
msg_Err (p_access, "read error: %s", vlc_strerror_c(errno)); msg_Err (p_access, "read error: %s", vlc_strerror_c(errno));
dialog_Fatal (p_access, _("File reading failed"),
_("VLC could not read the file (%s)."),
vlc_strerror(errno));
val = 0; val = 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment