Commit 067f8396 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-14132 follow-up fix: Make os_file_get_size() thread-safe

os_file_get_size(): Use fstat() instead of calling lseek() 3 times.
In this way, concurrent calls to this function should not interfere
with each other.

Suggested by Vladislav Vaintroub.
parent 9dfe84d5
......@@ -3238,17 +3238,10 @@ os_file_close_func(
@param[in] file handle to an open file
@return file size, or (os_offset_t) -1 on failure */
os_offset_t
os_file_get_size(
os_file_t file)
os_file_get_size(os_file_t file)
{
/* Store current position */
os_offset_t pos = lseek(file, 0, SEEK_CUR);
os_offset_t file_size = lseek(file, 0, SEEK_END);
/* Restore current position as the function should not change it */
lseek(file, pos, SEEK_SET);
return(file_size);
struct stat statbuf;
return fstat(file, &statbuf) ? os_offset_t(-1) : statbuf.st_size;
}
/** Gets a file size.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment