mirror of
https://github.com/MariaDB/server.git
synced 2026-10-23 18:49:29 +03:00
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.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user