imapext-2007

diff src/osdep/nt/write.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/osdep/nt/write.c	Mon Sep 14 15:17:45 2009 +0900
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* ========================================================================
     1.5 + * Copyright 1988-2006 University of Washington
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *     http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * 
    1.14 + * ========================================================================
    1.15 + */
    1.16 +
    1.17 +/*
    1.18 + * Program:	Write data, treating partial writes as an error
    1.19 + *
    1.20 + * Author:	Mark Crispin
    1.21 + *		Networks and Distributed Computing
    1.22 + *		Computing & Communications
    1.23 + *		University of Washington
    1.24 + *		Administration Building, AG-44
    1.25 + *		Seattle, WA  98195
    1.26 + *		Internet: MRC@CAC.Washington.EDU
    1.27 + *
    1.28 + * Date:	26 May 1995
    1.29 + * Last Edited:	30 August 2006
    1.30 + */
    1.31 +
    1.32 +/*  The whole purpose of this unfortunate routine is to deal with DOS and
    1.33 + * certain cretinous versions of UNIX which decided that the "bytes actually
    1.34 + * written" return value from write() gave them license to use that for things
    1.35 + * that are really errors, such as disk quota exceeded, maximum file size
    1.36 + * exceeded, disk full, etc.
    1.37 + * 
    1.38 + *  BSD won't screw us this way on the local filesystem, but who knows what
    1.39 + * some NFS-mounted filesystem will do.
    1.40 + */
    1.41 +
    1.42 +#undef write
    1.43 +
    1.44 +/* Write data to file
    1.45 + * Accepts: file descriptor
    1.46 + *	    I/O vector structure
    1.47 + *	    number of vectors in structure
    1.48 + * Returns: number of bytes written if successful, -1 if failure
    1.49 + */
    1.50 +
    1.51 +long maxposint = (long)((((unsigned long) 1) << ((sizeof(int) * 8) - 1)) - 1);
    1.52 +
    1.53 +long safe_write (int fd,char *buf,long nbytes)
    1.54 +{
    1.55 +  long i,j;
    1.56 +  if (nbytes > 0) for (i = nbytes; i; i -= j,buf += j) {
    1.57 +    while (((j = write (fd,buf,(int) min (maxposint,i))) < 0) &&
    1.58 +	   (errno == EINTR));
    1.59 +    if (j < 0) return j;
    1.60 +  }
    1.61 +  return nbytes;
    1.62 +}

UW-IMAP'd extensions by yuuji