title: Why does write continuously leave 4K bytes in the buffer?
body: <p>I have essentially the following code:</p>
  
  <pre><code>int fileWrite(int file, void * pBuffer, size_t size)
  {
      size_t bytesWritten = (size_t)write( file, pBuffer, size ) ;
      if (bytesWritten != size)
      {
         return -1;
      }
      return 0;
  }
  </code></pre>
  
  <p>It works if the size is 1GB, but when the size is ~2GB, it get 4K bytes left consistently. I can fix this by wrapping write in a loop and moving the buffer up but I'm curious as to why it is always failing.</p>
  
  <p>For example if size is 2147483648, write only writes 2147479552, leaving 4096 unwritten. Why would this happen and is it correct to always wrap write in a loop?</p>