1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/readv.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,119 @@
1.4 +/*-
1.5 + * © Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
1.6 + * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan
1.7 + * (Royal Institute of Technology, Stockholm, Sweden).
1.8 + * All rights reserved.
1.9 + *
1.10 + * Redistribution and use in source and binary forms, with or without
1.11 + * modification, are permitted provided that the following conditions
1.12 + * are met:
1.13 + *
1.14 + * 1. Redistributions of source code must retain the above copyright
1.15 + * notice, this list of conditions and the following disclaimer.
1.16 + *
1.17 + * 2. Redistributions in binary form must reproduce the above copyright
1.18 + * notice, this list of conditions and the following disclaimer in the
1.19 + * documentation and/or other materials provided with the distribution.
1.20 + *
1.21 + * 3. Neither the name of the Institute nor the names of its contributors
1.22 + * may be used to endorse or promote products derived from this software
1.23 + * without specific prior written permission.
1.24 + *
1.25 + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
1.26 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.27 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.28 + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
1.29 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.30 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.31 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.32 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.33 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.34 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.35 + * SUCH DAMAGE.
1.36 + */
1.37 +
1.38 +#ifndef __SYMBIAN32__
1.39 +#ifdef HAVE_CONFIG_H
1.40 +#include <config.h>
1.41 +RCSID("$Id: readv.c,v 1.1.2.1.2.4 2006/11/23 11:59:59 sivanand Exp $");
1.42 +#endif
1.43 +
1.44 +#include "roken.h"
1.45 +
1.46 +#endif
1.47 +
1.48 +#include <sys/types.h>
1.49 +#include <sys/uio.h>
1.50 +#include <unistd.h>
1.51 +#include <stdlib.h>
1.52 +#include <errno.h>
1.53 +#include <string.h>
1.54 +#include <sys/syslimits.h>
1.55 +
1.56 +#define min(X , Y) ((X) < (Y) ? (X) :(Y) )
1.57 +
1.58 +
1.59 +EXPORT_C ssize_t
1.60 +readv(int d, const struct iovec *iov, int iovcnt)
1.61 +{
1.62 + ssize_t ret, nb;
1.63 + size_t tot = 0;
1.64 + int VecIter = 0 ;
1.65 + char *buf, *p;
1.66 +
1.67 + if(iovcnt > IOV_MAX)
1.68 + {
1.69 + errno = EINVAL ;
1.70 + return -1 ;
1.71 + }
1.72 + if(iovcnt < 0 )
1.73 + {
1.74 + errno = EINVAL ;
1.75 + return -1 ;
1.76 + }
1.77 +
1.78 + for(VecIter = 0; VecIter < iovcnt ; ++VecIter)
1.79 + {
1.80 + if(iov[VecIter].iov_base == NULL)
1.81 + {
1.82 + if(VecIter != 0)
1.83 + {
1.84 + break ; //Break from the for loop
1.85 + }
1.86 + errno = EFAULT ;
1.87 + return -1 ;
1.88 + }
1.89 + if((int)iov[VecIter].iov_len >= 0 )
1.90 + {
1.91 + tot += iov[VecIter].iov_len;
1.92 + }
1.93 +
1.94 + else
1.95 + {
1.96 + errno = EINVAL ;
1.97 + return -1 ;
1.98 + }
1.99 +
1.100 + }
1.101 +
1.102 + buf = malloc(tot);
1.103 +
1.104 + if (tot != 0 && buf == NULL) {
1.105 + errno = ENOMEM;
1.106 + return -1;
1.107 + }
1.108 +
1.109 + nb = ret = read (d, buf, tot);
1.110 + p = buf;
1.111 +
1.112 + while (nb > 0) {
1.113 + ssize_t cnt = min(nb, iov->iov_len);
1.114 + memcpy (iov->iov_base, p, cnt);
1.115 + p += cnt;
1.116 + nb -= cnt;
1.117 + iov += 1 ; //Newly added
1.118 + }
1.119 + free(buf);
1.120 + return ret;
1.121 +}
1.122 +