home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / libncftp / libncftp-3.2.5-src.zip / libncftp-3.2.5 / sio / PWrite.c < prev    next >
C/C++ Source or Header  |  2003-08-31  |  838b  |  46 lines

  1. #include "syshdrs.h"
  2. #ifdef PRAGMA_HDRSTOP
  3. #    pragma hdrstop
  4. #endif
  5.  
  6. int
  7. PWrite(int sfd, const char *const buf0, size_t size)
  8. {
  9.     write_return_t nwrote;
  10.     write_size_t nleft;
  11.     const char *buf = buf0;
  12.     DECL_SIGPIPE_VARS
  13.     
  14.     if ((buf == NULL) || (size == 0)) {
  15.         errno = EINVAL;
  16.         return (-1);
  17.     }
  18.     
  19.     IGNORE_SIGPIPE
  20.     nleft = (write_size_t) size;
  21.     forever {
  22.         nwrote = write(sfd, buf, nleft);
  23.         if (nwrote < 0) {
  24.             if (errno != EINTR) {
  25.                 nwrote = (write_return_t) size - (write_return_t) nleft;
  26.                 if (nwrote == 0)
  27.                     nwrote = (write_return_t) -1;
  28.                 goto done;
  29.             } else {
  30.                 errno = 0;
  31.                 nwrote = 0;
  32.                 /* Try again. */
  33.             }
  34.         }
  35.         nleft -= (write_size_t) nwrote;
  36.         if (nleft == 0)
  37.             break;
  38.         buf += nwrote;
  39.     }
  40.     nwrote = (write_return_t) size - (write_return_t) nleft;
  41.  
  42. done:
  43.     RESTORE_SIGPIPE
  44.     return ((int) nwrote);
  45. }    /* PWrite */
  46.