1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
3*49cdfc7eSAndroid Build Coastguard Worker *
4*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
5*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
6*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
7*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
8*49cdfc7eSAndroid Build Coastguard Worker *
9*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
10*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
13*49cdfc7eSAndroid Build Coastguard Worker *
14*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
15*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write to the Free Software
16*49cdfc7eSAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*49cdfc7eSAndroid Build Coastguard Worker */
18*49cdfc7eSAndroid Build Coastguard Worker
19*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************
20*49cdfc7eSAndroid Build Coastguard Worker * writen.c
21*49cdfc7eSAndroid Build Coastguard Worker ******************************************************************************/
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
24*49cdfc7eSAndroid Build Coastguard Worker
25*49cdfc7eSAndroid Build Coastguard Worker /* Write "n" bytes to a descriptor
26*49cdfc7eSAndroid Build Coastguard Worker Use instead of write() when fd is a stream socket. */
27*49cdfc7eSAndroid Build Coastguard Worker
writen(int fd,char * ptr,int nbytes)28*49cdfc7eSAndroid Build Coastguard Worker int writen(int fd, char *ptr, int nbytes)
29*49cdfc7eSAndroid Build Coastguard Worker {
30*49cdfc7eSAndroid Build Coastguard Worker int nleft, nwritten;
31*49cdfc7eSAndroid Build Coastguard Worker
32*49cdfc7eSAndroid Build Coastguard Worker nleft = nbytes;
33*49cdfc7eSAndroid Build Coastguard Worker while (nleft > 0) {
34*49cdfc7eSAndroid Build Coastguard Worker nwritten = write(fd, ptr, nleft);
35*49cdfc7eSAndroid Build Coastguard Worker if (nwritten <= 0)
36*49cdfc7eSAndroid Build Coastguard Worker return (nwritten); /* error */
37*49cdfc7eSAndroid Build Coastguard Worker nleft -= nwritten;
38*49cdfc7eSAndroid Build Coastguard Worker ptr += nwritten;
39*49cdfc7eSAndroid Build Coastguard Worker }
40*49cdfc7eSAndroid Build Coastguard Worker return (nbytes - nleft);
41*49cdfc7eSAndroid Build Coastguard Worker }
42