ftruncate.c 793 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
/**
 * Some tests for p_ftruncate() to ensure that
 * properly handles large (2Gb+) files.
 */

#include "clar_libgit2.h"

static const char *filename = "core_ftruncate.txt";
static int fd = -1;

11
void test_ftruncate__initialize(void)
12
{
13
	if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE"))
14 15 16 17 18
		cl_skip();

	cl_must_pass((fd = p_open(filename, O_CREAT | O_RDWR, 0644)));
}

19
void test_ftruncate__cleanup(void)
20 21 22 23 24 25 26 27 28 29
{
	if (fd < 0)
		return;

	p_close(fd);
	fd = 0;

	p_unlink(filename);
}

30
static void _extend(off64_t i64len)
31 32 33 34 35 36 37 38 39
{
	struct stat st;
	int error;

	cl_assert((error = p_ftruncate(fd, i64len)) == 0);
	cl_assert((error = p_fstat(fd, &st)) == 0);
	cl_assert(st.st_size == i64len);
}

40
void test_ftruncate__2gb(void)
41 42 43 44
{
	_extend(0x80000001);
}

45
void test_ftruncate__4gb(void)
46 47 48
{
	_extend(0x100000001);
}