Cross Reference: writev.c
xref
: /
osnet-11
/
usr
/
src
/
lib
/
libresolv2
/
common
/
bsd
/
writev.c
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
2
N/A
#
ifndef
LINT
2
N/A
static
const
char
rcsid
[] =
"$Id:
writev.c
,v 1.3 2005/04/27 04:56:13 sra Exp $"
;
2
N/A
#
endif
2
N/A
2
N/A
#
include
"
port_before.h
"
2
N/A
2
N/A
#
include
<
sys
/
types.h
>
2
N/A
#
include
<
sys
/
uio.h
>
2
N/A
#
include
<
sys
/
stat.h
>
2
N/A
#
include
<
sys
/
socket.h
>
2
N/A
2
N/A
#
include
"
port_after.h
"
2
N/A
2
N/A
#
ifndef
NEED_WRITEV
2
N/A
int
__bindcompat_writev
;
2
N/A
#
else
2
N/A
2
N/A
#
ifdef
_CRAY
2
N/A
#
define
OWN_WRITEV
2
N/A
int
2
N/A
__writev
(
int
fd
,
struct
iovec
*
iov
,
int
iovlen
)
2
N/A
{
2
N/A
struct
stat
statbuf
;
2
N/A
2
N/A
if
(
fstat
(
fd
, &
statbuf
) < 0)
2
N/A
return
(-
1
);
2
N/A
2
N/A
/*
2
N/A
* Allow for atomic writes to network.
2
N/A
*/
2
N/A
if
(
statbuf
.
st_mode
&
S_IFSOCK
) {
2
N/A
struct
msghdr
mesg
;
2
N/A
2
N/A
memset
(&
mesg
, 0,
sizeof
(
mesg
));
2
N/A
mesg
.
msg_name
= 0;
2
N/A
mesg
.
msg_namelen
= 0;
2
N/A
mesg
.
msg_iov
=
iov
;
2
N/A
mesg
.
msg_iovlen
=
iovlen
;
2
N/A
mesg
.
msg_accrights
= 0;
2
N/A
mesg
.
msg_accrightslen
= 0;
2
N/A
return
(
sendmsg
(
fd
, &
mesg
, 0));
2
N/A
}
else
{
2
N/A
struct
iovec
*
tv
;
2
N/A
int
i,
rcode
= 0,
count
= 0;
2
N/A
2
N/A
for
(i = 0,
tv
=
iov
; i <=
iovlen
;
tv
++) {
2
N/A
rcode
=
write
(
fd
,
tv
->
iov_base
,
tv
->
iov_len
);
2
N/A
2
N/A
if
(
rcode
< 0)
2
N/A
break
;
2
N/A
2
N/A
count
+=
rcode
;
2
N/A
}
2
N/A
2
N/A
if
(
count
== 0)
2
N/A
return
(
rcode
);
2
N/A
else
2
N/A
return
(
count
);
2
N/A
}
2
N/A
}
2
N/A
2
N/A
#
else
/*_CRAY*/
2
N/A
2
N/A
int
2
N/A
__writev
(
fd
,
vp
,
vpcount
)
2
N/A
int
fd
;
2
N/A
const
struct
iovec
*
vp
;
2
N/A
int
vpcount
;
2
N/A
{
2
N/A
int
count
= 0;
2
N/A
2
N/A
while
(
vpcount
-- > 0) {
2
N/A
int
written
=
write
(
fd
,
vp
->
iov_base
,
vp
->
iov_len
);
2
N/A
2
N/A
if
(
written
< 0)
2
N/A
return
(-
1
);
2
N/A
count
+=
written
;
2
N/A
if
(
written
!=
vp
->
iov_len
)
2
N/A
break
;
2
N/A
vp
++;
2
N/A
}
2
N/A
return
(
count
);
2
N/A
}
2
N/A
2
N/A
#
endif
/*_CRAY*/
2
N/A
2
N/A
#
endif
/*NEED_WRITEV*/
2
N/A
2
N/A
/*! \file */