Include <kernel-features.h>.
[glibc/history.git] / io / tst-posix_fallocate.c
blob53f0704c34c4e52167ef9c11ec8f3ecef5675e4b
1 #include <fcntl.h>
2 #include <sys/stat.h>
4 static void do_prepare (void);
5 #define PREPARE(argc, argv) do_prepare ()
6 static int do_test (void);
7 #define TEST_FUNCTION do_test ()
8 #include <test-skeleton.c>
10 static int fd;
12 static void
13 do_prepare (void)
15 fd = create_temp_file ("tst-posix_fallocate.", NULL);
16 if (fd == -1)
18 printf ("cannot create temporary file: %m\n");
19 exit (1);
24 static int
25 do_test (void)
27 struct stat64 st;
29 if (fstat64 (fd, &st) != 0)
31 puts ("1st fstat failed");
32 return 1;
35 if (st.st_size != 0)
37 puts ("file not created with size 0");
38 return 1;
41 if (posix_fallocate (fd, 512, 768) != 0)
43 puts ("1st posix_fallocate call failed");
44 return 1;
47 if (fstat64 (fd, &st) != 0)
49 puts ("2nd fstat failed");
50 return 1;
53 if (st.st_size != 512 + 768)
55 printf ("file size after first posix_fallocate call is %llu, expected %u\n",
56 (unsigned long long int) st.st_size, 512u + 768u);
57 return 1;
60 if (posix_fallocate (fd, 0, 1024) != 0)
62 puts ("2nd posix_fallocate call failed");
63 return 1;
66 if (fstat64 (fd, &st) != 0)
68 puts ("3rd fstat failed");
69 return 1;
72 if (st.st_size != 512 + 768)
74 puts ("file size changed in second posix_fallocate");
75 return 1;
78 if (posix_fallocate (fd, 2048, 64) != 0)
80 puts ("3rd posix_fallocate call failed");
81 return 1;
84 if (fstat64 (fd, &st) != 0)
86 puts ("4th fstat failed");
87 return 1;
90 if (st.st_size != 2048 + 64)
92 printf ("file size after first posix_fallocate call is %llu, expected %u\n",
93 (unsigned long long int) st.st_size, 2048u + 64u);
94 return 1;
97 close (fd);
99 return 0;