1 /* @(#)nixwrite.c	1.5 04/08/08 Copyright 1986, 2001-2003 J. Schilling */
2 /*
3  *	Non interruptable extended write
4  *
5  *	Copyright (c) 1986, 2001-2003 J. Schilling
6  */
7 /*
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along with
19  * this program; see the file COPYING.  If not, write to the Free Software
20  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */
22 
23 #include "schilyio.h"
24 #include <errno.h>
25 
26 EXPORT int
_nixwrite(f,buf,count)27 _nixwrite(f, buf, count)
28 	int	f;
29 	void	*buf;
30 	int	count;
31 {
32 	register char *p = (char *)buf;
33 	register int ret;
34 	register int total = 0;
35 		int	oerrno = geterrno();
36 
37 	while (count > 0) {
38 		while ((ret = write(f, p, count)) < 0) {
39 			if (geterrno() == EINTR) {
40 				/*
41 				 * Set back old 'errno' so we don't change the
42 				 * errno visible to the outside if we did
43 				 * not fail.
44 				 */
45 				seterrno(oerrno);
46 				continue;
47 			}
48 			return (ret);	/* Any other error */
49 		}
50 		if (ret == 0)		/* EOF */
51 			break;
52 
53 		total += ret;
54 		count -= ret;
55 		p += ret;
56 	}
57 	return (total);
58 }
59