iovec.c revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <alloca.h>
#include <string.h>
#include <sys/lx_syscall.h>
#include <sys/lx_types.h>
static int
lx_is_directory(int fd)
{
}
int
{
if (lx_is_directory(fd))
return (-EISDIR);
return (-errno);
return (ret);
}
int
{
if (lx_is_directory(fd))
return (-EISDIR);
if (ret < 0)
return (-errno);
return (ret);
}
/*
* Implementation of Linux readv() and writev() system calls.
*
* The Linux system calls differ from the Solaris system calls in a few key
* areas:
*
* - On Solaris, the maximum number of I/O vectors that can be passed to readv()
* or writev() is IOV_MAX (16). Linux has a much larger restriction (1024).
*
* - Passing 0 as a vector count is an error on Solaris, but on Linux results
* in a return value of 0. Even though the man page says the opposite.
*
* - If the Nth vector results in an error, Solaris will return an error code
* for the entire operation. Linux only returns an error if there has been
* no data transferred yet. Otherwise, it returns the number of bytes
* transferred up until that point.
*
* In order to accomodate these differences, we implement these functions as a
* series of ordinary read() or write() calls.
*/
static int
{
int i;
return (-errno);
for (i = 0; i < count; i++) {
return (-EINVAL);
}
return (0);
}
int
{
int i;
if (count == 0)
return (0);
return (-EINVAL);
if (lx_is_directory(fd))
return (-EISDIR);
return (-ENOMEM);
return (ret);
for (i = 0; i < count; i++) {
if (ret < 0) {
if (total > 0)
return (total);
return (-errno);
}
}
return (total);
}
int
{
int i;
if (count == 0)
return (0);
return (-EINVAL);
return (-ENOMEM);
return (ret);
for (i = 0; i < count; i++) {
if (ret < 0) {
if (total > 0)
return (total);
return (-errno);
}
}
return (total);
}