sl@0
|
1 |
/*-
|
sl@0
|
2 |
* Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan
|
sl@0
|
3 |
* (Royal Institute of Technology, Stockholm, Sweden).
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*
|
sl@0
|
6 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
7 |
* modification, are permitted provided that the following conditions
|
sl@0
|
8 |
* are met:
|
sl@0
|
9 |
*
|
sl@0
|
10 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
11 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
12 |
*
|
sl@0
|
13 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
14 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
15 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
16 |
*
|
sl@0
|
17 |
* 3. Neither the name of the Institute nor the names of its contributors
|
sl@0
|
18 |
* may be used to endorse or promote products derived from this software
|
sl@0
|
19 |
* without specific prior written permission.
|
sl@0
|
20 |
*
|
sl@0
|
21 |
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
sl@0
|
22 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
23 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
24 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
sl@0
|
25 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
sl@0
|
26 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
sl@0
|
27 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
28 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
sl@0
|
29 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
sl@0
|
30 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
sl@0
|
31 |
* SUCH DAMAGE.
|
sl@0
|
32 |
* © Portions Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
sl@0
|
33 |
|
sl@0
|
34 |
*/
|
sl@0
|
35 |
|
sl@0
|
36 |
#ifndef __SYMBIAN32__
|
sl@0
|
37 |
#ifdef HAVE_CONFIG_H
|
sl@0
|
38 |
#include <config.h>
|
sl@0
|
39 |
RCSID("$Id: writev.c,v 1.1.2.1.2.4 2006/11/23 12:00:53 sivanand Exp $");
|
sl@0
|
40 |
#endif
|
sl@0
|
41 |
#include "roken.h"
|
sl@0
|
42 |
#endif
|
sl@0
|
43 |
|
sl@0
|
44 |
#include <sys/types.h>
|
sl@0
|
45 |
#include <sys/uio.h>
|
sl@0
|
46 |
#include <unistd.h>
|
sl@0
|
47 |
#include <stdlib.h>
|
sl@0
|
48 |
#include <errno.h>
|
sl@0
|
49 |
#include <string.h>
|
sl@0
|
50 |
#include <sys/syslimits.h>
|
sl@0
|
51 |
#include <stdio.h>
|
sl@0
|
52 |
#include <wchar.h>
|
sl@0
|
53 |
|
sl@0
|
54 |
|
sl@0
|
55 |
ssize_t
|
sl@0
|
56 |
_writev(int d, const struct iovec *iov, int iovcnt)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
ssize_t ret;
|
sl@0
|
59 |
size_t tot = 0;
|
sl@0
|
60 |
int VecIter;
|
sl@0
|
61 |
char *buf, *p;
|
sl@0
|
62 |
|
sl@0
|
63 |
if(iovcnt > IOV_MAX)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
errno = EINVAL ;
|
sl@0
|
66 |
return -1 ;
|
sl@0
|
67 |
}
|
sl@0
|
68 |
if(iovcnt < 0 )
|
sl@0
|
69 |
{
|
sl@0
|
70 |
errno = EINVAL ;
|
sl@0
|
71 |
return -1 ;
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
for(VecIter = 0; VecIter < iovcnt; ++VecIter)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
if(iov[VecIter].iov_base == NULL)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
if(VecIter != 0 )
|
sl@0
|
79 |
{
|
sl@0
|
80 |
break ; //Break From the for loop
|
sl@0
|
81 |
}
|
sl@0
|
82 |
errno = EFAULT ;
|
sl@0
|
83 |
return -1 ;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
if((int)iov[VecIter].iov_len >= 0 )
|
sl@0
|
87 |
{
|
sl@0
|
88 |
tot += iov[VecIter].iov_len;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
else
|
sl@0
|
92 |
{
|
sl@0
|
93 |
errno = EINVAL ;
|
sl@0
|
94 |
return -1 ;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
}
|
sl@0
|
98 |
buf = malloc(tot);
|
sl@0
|
99 |
if (tot != 0 && buf == NULL) {
|
sl@0
|
100 |
errno = ENOMEM;
|
sl@0
|
101 |
return -1;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
p = buf;
|
sl@0
|
104 |
for (VecIter = 0; VecIter < iovcnt; ++VecIter) {
|
sl@0
|
105 |
|
sl@0
|
106 |
if(iov[VecIter].iov_base == NULL)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
break ; //Break from the for loop
|
sl@0
|
109 |
}
|
sl@0
|
110 |
memcpy (p, iov[VecIter].iov_base, iov[VecIter].iov_len);
|
sl@0
|
111 |
p += iov[VecIter].iov_len;
|
sl@0
|
112 |
}
|
sl@0
|
113 |
ret = write (d, buf, tot);
|
sl@0
|
114 |
free (buf);
|
sl@0
|
115 |
return ret;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
#ifdef __SYMBIAN_COMPILE_UNUSED__
|
sl@0
|
119 |
ssize_t
|
sl@0
|
120 |
_wwritev(int d, const struct iovec *iov, int iovcnt)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
ssize_t ret;
|
sl@0
|
123 |
size_t tot = 0;
|
sl@0
|
124 |
int VecIter;
|
sl@0
|
125 |
FILE *fp ;
|
sl@0
|
126 |
|
sl@0
|
127 |
wchar_t *buf, *p;
|
sl@0
|
128 |
|
sl@0
|
129 |
if(iovcnt > IOV_MAX)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
errno = EINVAL ;
|
sl@0
|
132 |
return -1 ;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
if(iovcnt < 0 )
|
sl@0
|
135 |
{
|
sl@0
|
136 |
errno = EINVAL ;
|
sl@0
|
137 |
return -1 ;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
for(VecIter = 0; VecIter < iovcnt; ++VecIter)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
if(iov[VecIter].iov_base == NULL)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
if(VecIter != 0 )
|
sl@0
|
145 |
{
|
sl@0
|
146 |
break ; //Break From the for loop
|
sl@0
|
147 |
}
|
sl@0
|
148 |
errno = EFAULT ;
|
sl@0
|
149 |
return -1 ;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
if((int)iov[VecIter].iov_len >= 0 )
|
sl@0
|
153 |
{
|
sl@0
|
154 |
tot += iov[VecIter].iov_len;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
else
|
sl@0
|
158 |
{
|
sl@0
|
159 |
errno = EINVAL ;
|
sl@0
|
160 |
return -1 ;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
}
|
sl@0
|
164 |
buf = (wchar_t *)malloc(tot*sizeof(wchar_t));
|
sl@0
|
165 |
if (tot != 0 && buf == NULL) {
|
sl@0
|
166 |
errno = ENOMEM;
|
sl@0
|
167 |
return -1;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
p = buf;
|
sl@0
|
170 |
for (VecIter = 0; VecIter < iovcnt; ++VecIter)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
|
sl@0
|
173 |
if(iov[VecIter].iov_base == NULL)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
break ; //Break from the for loop
|
sl@0
|
176 |
}
|
sl@0
|
177 |
wmemcpy (p, iov[VecIter].iov_base, iov[VecIter].iov_len);
|
sl@0
|
178 |
p += iov[VecIter].iov_len;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
fp = fdopen(d,"a+");
|
sl@0
|
181 |
ret = fwprintf(fp,buf);
|
sl@0
|
182 |
//ret = write (d, buf, tot);
|
sl@0
|
183 |
free (buf);
|
sl@0
|
184 |
return ret;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
#endif //__SYMBIAN_COMPILE_UNUSED__
|
sl@0
|
188 |
|
sl@0
|
189 |
EXPORT_C
|
sl@0
|
190 |
writev(int fd, const struct iovec *iov, int iovcnt)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
return _writev(fd , iov , iovcnt) ;
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
|