annotate src/osdep/unix/write.c @ 0:ada5e610ab86

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

yatex.org