mirror of
https://github.com/MariaDB/server.git
synced 2025-01-23 23:34:34 +01:00
311d8e898f
include/maria.h: mac compiler warnings fixed. storage/maria/ma_bitmap.c: mac compiler warnings fixed. storage/maria/ma_blockrec.c: mac compiler warnings fixed. storage/maria/ma_check.c: mac compiler warnings fixed. storage/maria/ma_control_file.c: mac compiler warnings fixed. storage/maria/ma_create.c: mac compiler warnings fixed. storage/maria/ma_delete.c: mac compiler warnings fixed. storage/maria/ma_ft_boolean_search.c: mac compiler warnings fixed. storage/maria/ma_page.c: mac compiler warnings fixed. storage/maria/ma_pagecache.c: mac compiler warnings fixed. storage/maria/ma_recovery.c: mac compiler warning fixed. storage/maria/ma_rt_test.c: mac compiler warnings fixed. storage/maria/ma_search.c: mac compiler warning fixed. storage/maria/ma_write.c: mac compiler warnings fixed. storage/maria/unittest/ma_control_file-t.c: mac compiler warnings fixed. storage/maria/unittest/ma_pagecache_consist.c: mac compiler warnings fixed. storage/maria/unittest/ma_pagecache_single.c: mac compiler warnings fixed. storage/maria/unittest/ma_test_loghandler_pagecache-t.c: mac compiler warning fixed. storage/maria/unittest/test_file.c: mac compiler warning fixed.
103 lines
2.7 KiB
C
103 lines
2.7 KiB
C
#include <tap.h>
|
|
#include <my_sys.h>
|
|
#include <my_dir.h>
|
|
#include "test_file.h"
|
|
|
|
|
|
/*
|
|
Check that file contance correspond to descriptor
|
|
|
|
SYNOPSIS
|
|
test_file()
|
|
file File to test
|
|
file_name Path (and name) of file which is tested
|
|
size size of file
|
|
buff_size size of buffer which is enought to check the file
|
|
desc file descriptor to check with
|
|
|
|
RETURN
|
|
1 file if OK
|
|
0 error
|
|
*/
|
|
|
|
int test_file(PAGECACHE_FILE file, char *file_name,
|
|
off_t size, size_t buff_size, struct file_desc *desc)
|
|
{
|
|
unsigned char *buffr= my_malloc(buff_size, MYF(0));
|
|
off_t pos= 0;
|
|
size_t byte;
|
|
int step= 0;
|
|
int res= 1; /* ok */
|
|
|
|
#ifdef __WIN__
|
|
/*
|
|
On Windows, the info returned by stat(), specifically file length
|
|
is not necessarily current, because this is the behavior of
|
|
underlying FindFirstFile() function.
|
|
*/
|
|
WIN32_FILE_ATTRIBUTE_DATA file_attr;
|
|
LARGE_INTEGER li;
|
|
if(GetFileAttributesEx(file_name, GetFileExInfoStandard, &file_attr) == 0)
|
|
{
|
|
diag("Can't GetFileAttributesEx %s (errno: %d)\n", file_name,
|
|
GetLastError());
|
|
res= 0;
|
|
goto err;
|
|
}
|
|
li.HighPart= file_attr.nFileSizeHigh;
|
|
li.LowPart= file_attr.nFileSizeLow;
|
|
if(li.QuadPart != size)
|
|
{
|
|
diag("file %s size is %llu (should be %llu)\n",
|
|
file_name, (ulonglong)size, (ulonglong)li.QuadPart);
|
|
res= 0; /* failed */
|
|
/* continue to get more information */
|
|
}
|
|
#else
|
|
MY_STAT stat_buff, *stat;
|
|
if ((stat= my_stat(file_name, &stat_buff, MYF(0))) == NULL)
|
|
{
|
|
diag("Can't stat() %s (errno: %d)\n", file_name, errno);
|
|
res= 0;
|
|
goto err;
|
|
}
|
|
if (stat->st_size != size)
|
|
{
|
|
diag("file %s size is %lu (should be %lu)\n",
|
|
file_name, (ulong) stat->st_size, (ulong) size);
|
|
res= 0; /* failed */
|
|
/* continue to get more information */
|
|
}
|
|
#endif
|
|
|
|
/* check content */
|
|
my_seek(file.file, 0, SEEK_SET, MYF(MY_WME));
|
|
while (desc[step].length != 0)
|
|
{
|
|
if (my_read(file.file, buffr, desc[step].length, MYF(0)) !=
|
|
desc[step].length)
|
|
{
|
|
diag("Can't read %u bytes from %s (file: %d errno: %d)\n",
|
|
(uint)desc[step].length, file_name, file.file, errno);
|
|
res= 0;
|
|
goto err;
|
|
}
|
|
for (byte= 0; byte < desc[step].length; byte++)
|
|
{
|
|
if (buffr[byte] != desc[step].content)
|
|
{
|
|
diag("content of %s mismatch 0x%x in position %lu instead of 0x%x\n",
|
|
file_name, (uint) buffr[byte], (ulong) (pos + byte),
|
|
desc[step].content);
|
|
res= 0;
|
|
goto err;
|
|
}
|
|
}
|
|
pos+= desc[step].length;
|
|
step++;
|
|
}
|
|
|
|
err:
|
|
my_free(buffr, 0);
|
|
return res;
|
|
}
|