1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/writev.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,195 @@
1.4 +/*-
1.5 + * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan
1.6 + * (Royal Institute of Technology, Stockholm, Sweden).
1.7 + * All rights reserved.
1.8 + *
1.9 + * Redistribution and use in source and binary forms, with or without
1.10 + * modification, are permitted provided that the following conditions
1.11 + * are met:
1.12 + *
1.13 + * 1. Redistributions of source code must retain the above copyright
1.14 + * notice, this list of conditions and the following disclaimer.
1.15 + *
1.16 + * 2. Redistributions in binary form must reproduce the above copyright
1.17 + * notice, this list of conditions and the following disclaimer in the
1.18 + * documentation and/or other materials provided with the distribution.
1.19 + *
1.20 + * 3. Neither the name of the Institute nor the names of its contributors
1.21 + * may be used to endorse or promote products derived from this software
1.22 + * without specific prior written permission.
1.23 + *
1.24 + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
1.25 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.26 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.27 + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
1.28 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.29 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.30 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.31 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.32 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.33 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.34 + * SUCH DAMAGE.
1.35 + * © Portions Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.36 +
1.37 + */
1.38 +
1.39 +#ifndef __SYMBIAN32__
1.40 +#ifdef HAVE_CONFIG_H
1.41 +#include <config.h>
1.42 +RCSID("$Id: writev.c,v 1.1.2.1.2.4 2006/11/23 12:00:53 sivanand Exp $");
1.43 +#endif
1.44 +#include "roken.h"
1.45 +#endif
1.46 +
1.47 +#include <sys/types.h>
1.48 +#include <sys/uio.h>
1.49 +#include <unistd.h>
1.50 +#include <stdlib.h>
1.51 +#include <errno.h>
1.52 +#include <string.h>
1.53 +#include <sys/syslimits.h>
1.54 +#include <stdio.h>
1.55 +#include <wchar.h>
1.56 +
1.57 +
1.58 +ssize_t
1.59 +_writev(int d, const struct iovec *iov, int iovcnt)
1.60 +{
1.61 + ssize_t ret;
1.62 + size_t tot = 0;
1.63 + int VecIter;
1.64 + char *buf, *p;
1.65 +
1.66 + if(iovcnt > IOV_MAX)
1.67 + {
1.68 + errno = EINVAL ;
1.69 + return -1 ;
1.70 + }
1.71 + if(iovcnt < 0 )
1.72 + {
1.73 + errno = EINVAL ;
1.74 + return -1 ;
1.75 + }
1.76 +
1.77 + for(VecIter = 0; VecIter < iovcnt; ++VecIter)
1.78 + {
1.79 + if(iov[VecIter].iov_base == NULL)
1.80 + {
1.81 + if(VecIter != 0 )
1.82 + {
1.83 + break ; //Break From the for loop
1.84 + }
1.85 + errno = EFAULT ;
1.86 + return -1 ;
1.87 + }
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 + buf = malloc(tot);
1.102 + if (tot != 0 && buf == NULL) {
1.103 + errno = ENOMEM;
1.104 + return -1;
1.105 + }
1.106 + p = buf;
1.107 + for (VecIter = 0; VecIter < iovcnt; ++VecIter) {
1.108 +
1.109 + if(iov[VecIter].iov_base == NULL)
1.110 + {
1.111 + break ; //Break from the for loop
1.112 + }
1.113 + memcpy (p, iov[VecIter].iov_base, iov[VecIter].iov_len);
1.114 + p += iov[VecIter].iov_len;
1.115 + }
1.116 + ret = write (d, buf, tot);
1.117 + free (buf);
1.118 + return ret;
1.119 +}
1.120 +
1.121 +#ifdef __SYMBIAN_COMPILE_UNUSED__
1.122 +ssize_t
1.123 +_wwritev(int d, const struct iovec *iov, int iovcnt)
1.124 +{
1.125 + ssize_t ret;
1.126 + size_t tot = 0;
1.127 + int VecIter;
1.128 + FILE *fp ;
1.129 +
1.130 + wchar_t *buf, *p;
1.131 +
1.132 + if(iovcnt > IOV_MAX)
1.133 + {
1.134 + errno = EINVAL ;
1.135 + return -1 ;
1.136 + }
1.137 + if(iovcnt < 0 )
1.138 + {
1.139 + errno = EINVAL ;
1.140 + return -1 ;
1.141 + }
1.142 +
1.143 + for(VecIter = 0; VecIter < iovcnt; ++VecIter)
1.144 + {
1.145 + if(iov[VecIter].iov_base == NULL)
1.146 + {
1.147 + if(VecIter != 0 )
1.148 + {
1.149 + break ; //Break From the for loop
1.150 + }
1.151 + errno = EFAULT ;
1.152 + return -1 ;
1.153 + }
1.154 +
1.155 + if((int)iov[VecIter].iov_len >= 0 )
1.156 + {
1.157 + tot += iov[VecIter].iov_len;
1.158 + }
1.159 +
1.160 + else
1.161 + {
1.162 + errno = EINVAL ;
1.163 + return -1 ;
1.164 + }
1.165 +
1.166 + }
1.167 + buf = (wchar_t *)malloc(tot*sizeof(wchar_t));
1.168 + if (tot != 0 && buf == NULL) {
1.169 + errno = ENOMEM;
1.170 + return -1;
1.171 + }
1.172 + p = buf;
1.173 + for (VecIter = 0; VecIter < iovcnt; ++VecIter)
1.174 + {
1.175 +
1.176 + if(iov[VecIter].iov_base == NULL)
1.177 + {
1.178 + break ; //Break from the for loop
1.179 + }
1.180 + wmemcpy (p, iov[VecIter].iov_base, iov[VecIter].iov_len);
1.181 + p += iov[VecIter].iov_len;
1.182 + }
1.183 + fp = fdopen(d,"a+");
1.184 + ret = fwprintf(fp,buf);
1.185 + //ret = write (d, buf, tot);
1.186 + free (buf);
1.187 + return ret;
1.188 +}
1.189 +
1.190 +#endif //__SYMBIAN_COMPILE_UNUSED__
1.191 +
1.192 +EXPORT_C
1.193 +writev(int fd, const struct iovec *iov, int iovcnt)
1.194 +{
1.195 + return _writev(fd , iov , iovcnt) ;
1.196 +}
1.197 +
1.198 +