1 /* @(#)niwrite.c 1.7 09/06/30 Copyright 1986, 2001-2009 J. Schilling */
2 /*
3 * Non interruptable 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
_niwrite(f,buf,count)24 _niwrite(f, buf, count)
25 int f;
26 void *buf;
27 size_t count;
28 {
29 ssize_t ret;
30 int oerrno = geterrno();
31
32 if ((ret = (ssize_t)count) < 0) {
33 seterrno(EINVAL);
34 return ((ssize_t)-1);
35 }
36 while ((ret = write(f, buf, count)) < 0 && geterrno() == EINTR) {
37 /*
38 * Set back old 'errno' so we don't change the errno visible
39 * to the outside if we did not fail.
40 */
41 seterrno(oerrno);
42 }
43 return (ret);
44 }
45