title: How can I swap contents of two text files with kernel system calls
body: <p>Here is my poor attempt:</p>
  
  <pre><code>//open:
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  //raad, write, exit:
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  //renameat2:
  #include&lt;stdio.h&gt;
  
  int main(){
          int fd1, fd2;
          //do I need those ifs?
          if((fd1 = open("foo", O_RDWR)) == -1){
              write(2, "File failed to open in read/write mode\n", 33);
              exit(-1);
          }
  
          if((fd2 = open("bar", O_RDWR)) == -1 ){
              write(2, "File failed to open in read/write mode\n", 34);
              exit(-1);
          }
  
          renameat2(AT_FDCWD,fd1,AT_FDCWD,fd2, RENAME_EXCHANGE);
  
          close(fd1);
          close(fd2);
          exit(0);
  }
  </code></pre>
  
  <p>I'm trying to use the system call function "renameat2", but it gives me errors:</p>
  
  <p>main.c:24:3: warning: implicit declaration of function 'renameat2'; did you mean 'rename'?</p>
  
  <p>main.c:24:13: error: 'AT_FDCWD' undeclared (first use in this function)</p>
  
  <p>main.c:24:40: error: 'RENAME_EXCHANGE' undeclared (first use in this function)</p>