common: kill _supported_os
[xfstests-dev.git] / src / t_rename_overwrite.c
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <err.h>
4 #include <sys/stat.h>
5
6 int main(int argc, char *argv[])
7 {
8         const char *path1;
9         const char *path2;
10         struct stat stbuf;
11         int res;
12         int fd;
13
14         if (argc != 3) {
15                 fprintf(stderr, "usage: %s path1 path2\n", argv[0]);
16                 return 1;
17         }
18
19         path1 = argv[1];
20         path2 = argv[2];
21         fd = open(path2, O_RDONLY);
22         if (fd == -1)
23                 err(1, "open(\"%s\")", path2);
24
25         res = rename(path1, path2);
26         if (res == -1)
27                 err(1, "rename(\"%s\", \"%s\")", path1, path2);
28
29         res = fstat(fd, &stbuf);
30         if (res == -1)
31                 err(1, "fstat(%i)", fd);
32
33         if (stbuf.st_nlink != 0) {
34                 fprintf(stderr, "nlink is %lu, should be 0\n",
35                         (unsigned long) stbuf.st_nlink);
36                 return 1;
37         }
38
39         return 0;
40 }