1
/* ========================================================================
2
* Copyright 1988-2006 University of Washington
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
11
* ========================================================================
15
* Program: Write data, treating partial writes as an error
17
* Author: Mark Crispin
18
* Networks and Distributed Computing
19
* Computing & Communications
20
* University of Washington
21
* Administration Building, AG-44
23
* Internet: MRC@CAC.Washington.EDU
26
* Last Edited: 30 August 2006
29
/* The whole purpose of this unfortunate routine is to deal with DOS and
30
* certain cretinous versions of UNIX which decided that the "bytes actually
31
* written" return value from write() gave them license to use that for things
32
* that are really errors, such as disk quota exceeded, maximum file size
33
* exceeded, disk full, etc.
35
* BSD won't screw us this way on the local filesystem, but who knows what
36
* some NFS-mounted filesystem will do.
42
* Accepts: file descriptor
43
* I/O vector structure
44
* number of vectors in structure
45
* Returns: number of bytes written if successful, -1 if failure
48
long maxposint = (long)((((unsigned long) 1) << ((sizeof(int) * 8) - 1)) - 1);
50
long safe_write (int fd,char *buf,long nbytes)
53
if (nbytes > 0) for (i = nbytes; i; i -= j,buf += j) {
54
while (((j = write (fd,buf,(int) min (maxposint,i))) < 0) &&