Commit c8c7d545 authored by KO Myung-Hun's avatar KO Myung-Hun Committed by Rémi Denis-Courmont

os2: filesystem: implement vlc_write() and vlc_writev()

Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent c932b5e7
......@@ -39,6 +39,7 @@
#include <sys/stat.h>
#include <dirent.h>
#include <sys/socket.h>
#include <signal.h>
#include <vlc_common.h>
#include <vlc_charset.h>
......@@ -346,6 +347,46 @@ int vlc_pipe (int fds[2])
return 0;
}
/**
* Writes data to a file descriptor. Unlike write(), if EPIPE error occurs,
* this function does not generate a SIGPIPE signal.
* @note If the file descriptor is known to be neither a pipe/FIFO nor a
* connection-oriented socket, the normal write() should be used.
*/
ssize_t vlc_write(int fd, const void *buf, size_t len)
{
struct iovec iov = { .iov_base = (void *)buf, .iov_len = len };
return vlc_writev(fd, &iov, 1);
}
/**
* Writes data from an iovec structure to a file descriptor. Unlike writev(),
* if EPIPE error occurs, this function does not generate a SIGPIPE signal.
*/
ssize_t vlc_writev(int fd, const struct iovec *iov, int count)
{
sigset_t set, oset;
sigemptyset(&set);
sigaddset(&set, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &set, &oset);
ssize_t val = writev(fd, iov, count);
if (val < 0 && errno == EPIPE)
{
siginfo_t info;
struct timespec ts = { 0, 0 };
while (sigtimedwait(&set, &info, &ts) >= 0 || errno != EAGAIN);
}
if (!sigismember(&oset, SIGPIPE)) /* Restore the signal mask if changed */
pthread_sigmask(SIG_SETMASK, &oset, NULL);
return val;
}
#include <vlc_network.h>
/**
......
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