1 /* @(#)nixwrite.c	1.7 09/06/30 Copyright 1986, 2001-2009 J. Schilling */
2 /*
3  *	Non interruptable extended write
4  *
5  *	Copyright (c) 1986, 2001-2009 J. Schilling
6  */
7 /*
8  * The contents of this file are subject to the terms of the
9  * Common Development and Distribution License, Version 1.0 only
10  * (the "License").  You may not use this file except in compliance
11  * with the License.
12  *
13  * See the file CDDL.Schily.txt in this distribution for details.
14  * A copy of the CDDL is also available via the Internet at
15  * http://www.opensource.org/licenses/cddl1.txt
16  *
17  * When distributing Covered Code, include this CDDL HEADER in each
18  * file and include the License file CDDL.Schily.txt from this distribution.
19  */
20 
21 #include "schilyio.h"
22 
23 EXPORT ssize_t
_nixwrite(f,buf,count)24 _nixwrite(f, buf, count)
25 	int	f;
26 	void	*buf;
27 	size_t	count;
28 {
29 	register char	*p = (char *)buf;
30 	register ssize_t ret;
31 	register int	total = 0;
32 		int	oerrno = geterrno();
33 
34 	if ((ret = (ssize_t)count) < 0) {
35 		seterrno(EINVAL);
36 		return ((ssize_t)-1);
37 	}
38 	while (count > 0) {
39 		while ((ret = write(f, p, count)) < 0) {
40 			if (geterrno() == EINTR) {
41 				/*
42 				 * Set back old 'errno' so we don't change the
43 				 * errno visible to the outside if we did
44 				 * not fail.
45 				 */
46 				seterrno(oerrno);
47 				continue;
48 			}
49 			return (ret);	/* Any other error */
50 		}
51 		if (ret == 0)		/* EOF */
52 			break;
53 
54 		total += ret;
55 		count -= ret;
56 		p += ret;
57 	}
58 	return (total);
59 }
60