title: How to write() data more than 2G in a time
body: <p>I have already defined <code>_LARGEFILE64_SOURCE</code> and  <code>_FILE_OFFSET_BITS 64</code> 
   to support open() file that more than 2G. That seems to be all right.</p>
  
  <p>But if I try to write() data more than 2G at a time ( such as 64G ), write() will return a value much smaller than 64G (Exactly 2147479552). I guess that write() only can write data smaller than 2G in a time.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#define _GNU_SOURCE
  #define _LARGEFILE_SOURCE
  #define _LARGEFILE64_SOURCE
  #define _FILE_OFFSET_BITS 64
  
  #include &lt;fcntl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;mmap.h&gt;
  
  #define SPACE_SIZE 68719476736
  
  int main()
  {
      ssize_t err;
      void* zeros;
      int fd = open64("./test", O_CREAT|O_RDWR|O_LARGEFILE, 0644);
      assert(fd != -1);
      int zero_fd = open("/dev/zero", O_RDWR);
      assert(zero_fd != -1);
  
      zeros = mmap(NULL, SPACE_SIZE, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, zero_fd, 0);
      assert(zeros != (void *)-1);
      err = write(fd, zeros, SPACE_SIZE);
      assert(err == SPACE_SIZE);   // Received SIGABRT, err = 2147479552
      munmap(zeros, SPACE_SIZE);
  }
  </code></pre>
  
  <p>How to write() data more than 2G in a time?</p>
  
  <p>Supplementary info:</p>
  
  <p>The result of <code>readelf -h ./a.out</code>. a.out is my program's name</p>
  
  <pre><code>ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Shared object file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x660
  Start of program headers:          64 (bytes into file)
  Start of section headers:          6672 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         9
  Size of section headers:           64 (bytes)
  Number of section headers:         29
  Section header string table index: 28
  </code></pre>