I have written a C++ program that passes data from a file to an FPGA board and back again using software and DMA buffers.
In my program I need to compare the size of a given file against a software buffer of size 3MB. This is needed so as to see which function to use to read from the file. As the files used range from very large (>30GB) to very small (<3MB), I have enabled large file support and I obtain the file size by using the fstat function.
I make sure that large file support is enabled in the header file
Expand|Select|Wrap|Line Numbers
- // Larger file support for files greater then 20 gigabytes
- #ifndef _LARGEFILE_SOURCE
- #define _LARGEFILE_SOURCE
- #endif
- #ifndef _LARGEFILE64_SOURCE
- #define _LARGEFILE64_SOURCE
- #endif
The code that I am using to compare the files is this
Expand|Select|Wrap|Line Numbers
- #define BUF_SIZE 0x300000
- ..
- ..
- ..
- ..
- ..
- struct stat statbuf;
- fstat(dat_fd, &statbuf); //where dat_fd is the file handler
- off64_t file_size = (off64_t)statbuf.st_size;
- off64_t temp_buf_size = (off64_t) BUF_SIZE; //software buffer
- if(temp_buf_size > file_size)
- {
- small_flag = true; //ie 1
- }
- else
- {
- small_flag = false; //ie 0
- }
Expand|Select|Wrap|Line Numbers
- Debug::writeDebug("file comparison results -> BUF_SIZE =%llu file_size =%llu small_flag =%d\n",
- temp_buf_size, file_size, small_flag);
Here are the debug outputs:
for file size = 1024000 bytes
Expand|Select|Wrap|Line Numbers
- file comparison results -> BUF_SIZE =3145728 file_size =1024000 small_flag =1
Expand|Select|Wrap|Line Numbers
- file comparison results -> BUF_SIZE =3145728 file_size =10240000 small_flag =0
Expand|Select|Wrap|Line Numbers
- file comparison results -> BUF_SIZE =3145728 file_size =18446744073074567528 small_flag =1
Does anyone have any idea why this simple comparison is not working?
Thanks
Lars