]> git.ipfire.org Git - thirdparty/glibc.git/blame - io/tst-posix_fallocate-common.c
build-many-glibcs.py: Add openrisc hard float glibc variant
[thirdparty/glibc.git] / io / tst-posix_fallocate-common.c
CommitLineData
45ff2bfc 1/* Common posix_fallocate tests definitions.
dff8da6b 2 Copyright (C) 2016-2024 Free Software Foundation, Inc.
45ff2bfc
AZ
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
45ff2bfc
AZ
18
19#include <fcntl.h>
c23de0aa
FW
20#include <limits.h>
21#include <stdint.h>
45ff2bfc 22#include <sys/stat.h>
c23de0aa 23#include <sys/types.h>
45ff2bfc
AZ
24#include <unistd.h>
25
c23de0aa
FW
26#include <support/support.h>
27#include <support/check.h>
28#include <support/temp_file.h>
45ff2bfc
AZ
29
30static char *temp_filename;
31static int temp_fd;
32
33static void
c23de0aa 34do_prepare (int argc, char **argv)
45ff2bfc
AZ
35{
36 temp_fd = create_temp_file ("tst-posix_fallocate.", &temp_filename);
37 if (temp_fd == -1)
38 FAIL_EXIT1 ("cannot create temporary file: %m\n");
39}
c23de0aa 40#define PREPARE do_prepare
45ff2bfc
AZ
41
42static int
43do_test_with_offset (off_t offset)
44{
45 struct stat st;
46
47 if (posix_fallocate (temp_fd, offset, 768) != 0)
48 FAIL_EXIT1 ("1st posix_fallocate call failed");
49
50 if (fstat (temp_fd, &st) != 0)
51 FAIL_EXIT1 ("2nd fstat failed");
52
53 if (st.st_size != (offset + 768))
54 FAIL_EXIT1 ("file size after first posix_fallocate call is %lu, "
55 "expected %lu",
56 (unsigned long int) st.st_size, 512lu + 768lu);
57
58 if (posix_fallocate (temp_fd, 0, 1024) != 0)
59 FAIL_EXIT1 ("2nd posix_fallocate call failed");
60
61 if (fstat (temp_fd, &st) != 0)
62 FAIL_EXIT1 ("3rd fstat failed");
63
64 if (st.st_size != (offset) + 768)
65 FAIL_EXIT1 ("file size changed in second posix_fallocate");
66
67 offset += 2048;
68 if (posix_fallocate (temp_fd, offset, 64) != 0)
69 FAIL_EXIT1 ("3rd posix_fallocate call failed");
70
71 if (fstat (temp_fd, &st) != 0)
72 FAIL_EXIT1 ("4th fstat failed");
73
74 if (st.st_size != (offset + 64))
75 FAIL_EXIT1 ("file size after first posix_fallocate call is %llu, "
76 "expected %u",
77 (unsigned long long int) st.st_size, 2048u + 64u);
78
79 return 0;
80}
c23de0aa
FW
81
82/* This function is defined by the individual tests. */
83static int do_test (void);
84
85#include <support/test-driver.c>