Skip to content

Instantly share code, notes, and snippets.

@estan
Created October 24, 2017 08:52
Show Gist options
  • Save estan/2bff46863ec503bbf13cc545cd8d385e to your computer and use it in GitHub Desktop.
Save estan/2bff46863ec503bbf13cc545cd8d385e to your computer and use it in GitHub Desktop.
renameat2 bug
[estan@newton renameat2tc]$ ls
totalt 24
-rw-rw-r-- 1 estan estan 6 okt 24 10:51 foo
-rw-rw-r-- 1 estan estan 317 okt 24 10:49 renameat2.c
[estan@newton renameat2tc]$ cat foo
hello
[estan@newton renameat2tc]$ cat renameat2.c
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/fs.h>
int main(int argc, char *argv[]) {
syscall(SYS_renameat2, AT_FDCWD, argv[1], AT_FDCWD, argv[2], RENAME_NOREPLACE);
printf("%s\n", strerror(errno));
return 0;
}
[estan@newton renameat2tc]$ gcc -o renameat2 renameat2.c
[estan@newton renameat2tc]$ ./renameat2 foo bar
Invalid argument
[estan@newton renameat2tc]$ touch bar
[estan@newton renameat2tc]$ ./renameat2 foo bar
File exists
[estan@newton renameat2tc]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment