Here is my poor attempt:
//open:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
//raad, write, exit:
#include <unistd.h>
#include <stdlib.h>
//renameat2:
#include<stdio.h>
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);
}
I'm trying to use the system call function "renameat2", but it gives me errors:
main.c:24:3: warning: implicit declaration of function 'renameat2'; did you mean 'rename'?
main.c:24:13: error: 'AT_FDCWD' undeclared (first use in this function)
main.c:24:40: error: 'RENAME_EXCHANGE' undeclared (first use in this function)