title: O_FLAGS to append or create file. With open() in C unix
body: <p>So I have the following code. The str_arr[] just contain combination of console commands ex ls, sort.. and filenames. And execute() forks a child process.</p>
  
  <pre><code>for(int y=0; y&lt;i-1; y++){
      if(type_arr[y]==0){
  
      }
      else if(type_arr[y]==1){
  
      }
      else if(type_arr[y]==2){
          int fw1=open(str_arr[y+1], O_WRONLY | O_APPEND | O_CREAT |S_IRWXU);
          int sv_out1=dup(1);
          dup2(fw1, 1);
          close(fw1);
          execute(str_arr[y]);
          dup2(sv_out1, 1);
      }
      else if(type_arr[y]==3){
          int fw=open(str_arr[y+1], O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IRGRP | S_IWGRP | S_IWUSR);
          int sv_out=dup(1);
          dup2(fw, 1);
          close(fw);
          execute(str_arr[y]);
          dup2(sv_out, 1);
      }
  }
  </code></pre>
  
  <p>when <strong>type_arr[y]==3</strong>, The code should create or overwrite file, if file exist. This works. However when <strong>type_arr[y]==2</strong> the code should create or append file, this does not work, in fact it only prints normally to console if file exist (using ls), if file does exist it does create a new file. Whats wrong here ? these O_FLAGS should append or create file right? </p>