xfs: test that the needsrepair feature works as advertised
[xfstests-dev.git] / src / t_truncate_self.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <errno.h>
4 #include <unistd.h>
5 #include <libgen.h>
6
7 int main(int argc, char *argv[])
8 {
9         const char *progname = basename(argv[0]);
10         int ret;
11
12         ret = truncate(argv[0], 4096);
13         if (ret != -1) {
14                 if (argc == 2 && strcmp(argv[1], "--may-succeed") == 0)
15                         return 0;
16                 fprintf(stderr, "truncate(%s) should have failed\n",
17                         progname);
18                 return 1;
19         }
20         if (errno != ETXTBSY) {
21                 perror(progname);
22                 return 1;
23         }
24
25         return 0;
26 }