~ubuntu-branches/debian/squeeze/alpine/squeeze

« back to all changes in this revision

Viewing changes to imap/src/osdep/os2/write.c

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2007-02-17 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070217131742-99x5c6cpg1pbkdhw
Tags: upstream-0.82+dfsg
ImportĀ upstreamĀ versionĀ 0.82+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ========================================================================
 
2
 * Copyright 1988-2006 University of Washington
 
3
 *
 
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
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * 
 
11
 * ========================================================================
 
12
 */
 
13
 
 
14
/*
 
15
 * Program:     Write data, treating partial writes as an error
 
16
 *
 
17
 * Author:      Mark Crispin
 
18
 *              Networks and Distributed Computing
 
19
 *              Computing & Communications
 
20
 *              University of Washington
 
21
 *              Administration Building, AG-44
 
22
 *              Seattle, WA  98195
 
23
 *              Internet: MRC@CAC.Washington.EDU
 
24
 *
 
25
 * Date:        26 May 1995
 
26
 * Last Edited: 30 August 2006
 
27
 */
 
28
 
 
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.
 
34
 * 
 
35
 *  BSD won't screw us this way on the local filesystem, but who knows what
 
36
 * some NFS-mounted filesystem will do.
 
37
 */
 
38
 
 
39
#undef write
 
40
 
 
41
/* Write data to file
 
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
 
46
 */
 
47
 
 
48
long maxposint = (long)((((unsigned long) 1) << ((sizeof(int) * 8) - 1)) - 1);
 
49
 
 
50
long safe_write (int fd,char *buf,long nbytes)
 
51
{
 
52
  long i,j;
 
53
  if (nbytes > 0) for (i = nbytes; i; i -= j,buf += j) {
 
54
    while (((j = write (fd,buf,(int) min (maxposint,i))) < 0) &&
 
55
           (errno == EINTR));
 
56
    if (j < 0) return j;
 
57
  }
 
58
  return nbytes;
 
59
}