title: Change named pipe buffer size in macOS
body: <p>Is there any way to control the buffer size of a named pipe created through <code>mkfifo</code>?</p>
  
  <p>I’m using macOS 10.13.2 and the buffer size seems fixed at 8192 bytes. I was able to get to that number with this snippet of code: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;thread&gt;
  
  #define BUFFER_SIZE 1024*1024
  #define FIFO_PATH "/Users/joao/Desktop/fifo"
  
  void readFifo() {
          auto fd = open(FIFO_PATH, O_RDONLY);
  
          if (fd &lt; 0) {
                  std::cerr &lt;&lt; "Failed to open fifo for reading" &lt;&lt; std::endl;
                  return;
          }
  
          std::cout &lt;&lt; "Ready to read!" &lt;&lt; std::endl;
  
          char buffer[BUFFER_SIZE];
          auto total_bytes_read = 0;
  
          while (total_bytes_read &lt; BUFFER_SIZE) {
                  auto bytes_read = read(fd, buffer, BUFFER_SIZE);
                  std::cout &lt;&lt; "Read " &lt;&lt; bytes_read &lt;&lt; " bytes" &lt;&lt; std::endl;
  
                  total_bytes_read += bytes_read;
          }
  
          close(fd);
  }
  
  int main(int argc, const char * argv[]) {
          unlink(FIFO_PATH);
  
          if (mkfifo(FIFO_PATH, 0666) != 0) {
                  std::cerr &lt;&lt; "Failed to create fifo" &lt;&lt; std::endl;
                  return 1;
          }
  
          std::thread reader(readFifo);
  
          auto fd = open(FIFO_PATH, O_WRONLY);
  
          if (fd &lt; 0) {
                  std::cerr &lt;&lt; "Failed to open fifo for writing" &lt;&lt; std::endl;
                  return 1;
          }
  
          char buffer[BUFFER_SIZE];
  
          for (int i = 0; i &lt; BUFFER_SIZE; i++) {
                  buffer[i] = 'a';
          }
  
          auto bytes_written = write(fd, buffer, BUFFER_SIZE);
  
          reader.join();
          std::cout &lt;&lt; "Wrote " &lt;&lt; bytes_written &lt;&lt; " bytes" &lt;&lt; std::endl;
  
          unlink(FIFO_PATH);
          return 0;
  }
  </code></pre>