title: Using O_RDWR vs O_RDONLY | O_WRONLY
body: <p>In my simple program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sstream&gt;
  
  using namespace std;
  
  int main(int argc, char *argv[]) {
      stringstream ss;
      ss &lt;&lt; "What does the quick brown fox say?" &lt;&lt; endl;
  
      int file_descriptor = open("/dev/tty", O_RDONLY | O_WRONLY);
      write(file_descriptor, ss.str().c_str(), ss.str().size());
  }
  </code></pre>
  
  <p>I open the terminal stream using the combination <code>O_RDONLY</code> | <code>O_WRONLY</code>, and this seems to work fine. I get that you <em>should</em> use <code>O_RDWR</code> because it makes clearer semantic sense, but my question is why bother creating a whole other flag if joining two existing flags already works? Is there some historical reason for this, or am I just overlooking something, and this really doesn't actually work?</p>