You can get the size of a file or folder in the following way, where FD is the file (folder) descriptor
Long fileSize = Lseek (FD, 0, Seek_end)
But the following problems exist
CT6.3
If the FD passed to Lseek is a regular file, there is no problem;
If the FD passed to Lseek is a directory, not a file, then a fixed value 9223372036854775807 (0x 7FFF FFFF FFFF FFFF) is returned, because the directory under Linux is also a file;
If the FD passed to Lseek is a non-empty directory, and the following files are not empty, then the values are still returned, rather than the size of all the files in the directory.
CT4.4
If the FD passed to Lseek is a regular file, there is no problem;
if the FD passed to Lseek is a directory (whether or not it is empty) instead of a file, then a fixed value 4096 is returned, because the directory under Linux is also a file
Either the CT4.4 4096 return value or the CT6.3 9223372036854775807 return value is incorrect. In fact, doing Lseek (FD, 0, Seek_end) on a directory is wrong .
If you do a lseek (FD, 0, Seek_end) operation on a directory, and the return value is considered a "file" size, for CT4.4, it's 4 K, but for CT6.3, it's tragic: 9223372036854775807, such a large number, if you load the file as a file size, and allocate so much memory space in advance, memory will burst, because 9223372036854775807 is 0x 7FFF FFFF FFFF FFFF = 2 ^ 63- 1, the equivalent of 2 ^ G.
The " Lseek (FD, 0, Seek_end) operations return Astronomical" scenario under the CT6.3 is a bug in the Lseek () function.