2014-08-13 10:39:27 +01:00
|
|
|
/*
|
|
|
|
* <sys/uio.h> wrapper functions.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Steffen Kiess (s-kiess@web.de)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Steffen Kiess
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#endif /* ndef _GNU_SOURCE */
|
|
|
|
|
2021-03-11 08:50:30 +00:00
|
|
|
#include <config.h>
|
|
|
|
#if defined(TARGET_MACH)
|
|
|
|
/* So we can use the declaration of preadv () */
|
|
|
|
#define _DARWIN_C_SOURCE
|
|
|
|
#endif
|
|
|
|
|
2016-08-03 10:59:49 +00:00
|
|
|
#include "sys-uio.h"
|
|
|
|
|
2014-08-13 10:39:27 +01:00
|
|
|
#include <sys/uio.h>
|
|
|
|
|
|
|
|
#include "map.h"
|
|
|
|
#include "mph.h"
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2016-08-03 10:59:49 +00:00
|
|
|
struct iovec*
|
|
|
|
_mph_from_iovec_array (struct Mono_Posix_Iovec *iov, gint32 iovcnt)
|
2014-08-13 10:39:27 +01:00
|
|
|
{
|
|
|
|
struct iovec* v;
|
|
|
|
gint32 i;
|
|
|
|
|
|
|
|
if (iovcnt < 0) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = malloc (iovcnt * sizeof (struct iovec));
|
|
|
|
if (!v) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
if (Mono_Posix_FromIovec (&iov[i], &v[i]) != 0) {
|
|
|
|
free (v);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_READV
|
|
|
|
gint64
|
|
|
|
Mono_Posix_Syscall_readv (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt)
|
|
|
|
{
|
|
|
|
struct iovec* v;
|
|
|
|
gint64 res;
|
|
|
|
|
2016-08-03 10:59:49 +00:00
|
|
|
v = _mph_from_iovec_array (iov, iovcnt);
|
2014-08-13 10:39:27 +01:00
|
|
|
if (!v) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = readv(dirfd, v, iovcnt);
|
|
|
|
free (v);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif /* def HAVE_READV */
|
|
|
|
|
|
|
|
#ifdef HAVE_WRITEV
|
|
|
|
gint64
|
|
|
|
Mono_Posix_Syscall_writev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt)
|
|
|
|
{
|
|
|
|
struct iovec* v;
|
|
|
|
gint64 res;
|
|
|
|
|
2016-08-03 10:59:49 +00:00
|
|
|
v = _mph_from_iovec_array (iov, iovcnt);
|
2014-08-13 10:39:27 +01:00
|
|
|
if (!v) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = writev (dirfd, v, iovcnt);
|
|
|
|
free (v);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif /* def HAVE_WRITEV */
|
|
|
|
|
|
|
|
#ifdef HAVE_PREADV
|
|
|
|
gint64
|
|
|
|
Mono_Posix_Syscall_preadv (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt, gint64 off)
|
|
|
|
{
|
|
|
|
struct iovec* v;
|
|
|
|
gint64 res;
|
|
|
|
|
|
|
|
mph_return_if_off_t_overflow (off);
|
|
|
|
|
2016-08-03 10:59:49 +00:00
|
|
|
v = _mph_from_iovec_array (iov, iovcnt);
|
2014-08-13 10:39:27 +01:00
|
|
|
if (!v) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = preadv (dirfd, v, iovcnt, (off_t) off);
|
|
|
|
free (v);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif /* def HAVE_PREADV */
|
|
|
|
|
|
|
|
#ifdef HAVE_PWRITEV
|
|
|
|
gint64
|
|
|
|
Mono_Posix_Syscall_pwritev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt, gint64 off)
|
|
|
|
{
|
|
|
|
struct iovec* v;
|
|
|
|
gint64 res;
|
|
|
|
|
|
|
|
mph_return_if_off_t_overflow (off);
|
|
|
|
|
2016-08-03 10:59:49 +00:00
|
|
|
v = _mph_from_iovec_array (iov, iovcnt);
|
2014-08-13 10:39:27 +01:00
|
|
|
if (!v) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = pwritev (dirfd, v, iovcnt, (off_t) off);
|
|
|
|
free (v);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif /* def HAVE_PWRITEV */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vim: noexpandtab
|
|
|
|
*/
|