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