Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 0.37 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Is there a cleaner way to use the C write function reliably?
  2. write
  3.        
  4. for (int n = 0; n < count; ) {
  5.     int ret = write(fd, (char *)buf + n, count - n);
  6.     if (ret < 0) {
  7.          if (errno == EINTR || errno == EAGAIN) continue; // try again
  8.          perror("write");
  9.          break;
  10.     } else {
  11.         n += ret;
  12.     }
  13. }
  14.  
  15. // if (n < count) here some error occurred