[bmx] Long Filesize by N [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:40

Previous topic - Next topic

BlitzBot

Title : Long Filesize
Author : N
Posted : 1+ years ago

Description : Basically, this is the same as FileSize, but uses a Long instead of an Int.  Win32 and Linux are the only platforms supported by this function currently.

If you find a way to do this on OS X, I encourage you to post it to save others time.  In the mean time, I'll be looking for a solution.


Code :
Code (blitzmax) Select
?Win32
Const FILE_READ_ATTRIBUTES% = $00000080
Const FILE_SHARE_READ% = $00000001
Const OPEN_EXISTING% = 3

Extern "OS"
    Function GetFileSizeEx:Int( handle%, size:Long Ptr )
    Function CreateFileW:Int( filename$W, daccess%, sharem%, seca@ Ptr, cDisp%, flags%, template% )
    Function CloseHandle:Int( handle% )
End Extern

?Linux
Private
Global statbank:TBank = TBank.Create(256) ' Maximum possible size
Public

Extern "OS"
    Function stat64:Int( path$z, buf@ Ptr )
End Extern

?MacOS

?

Function GetFileSize:Long( file$ )
    Local out:Long=-1
   
    ?Win32
    Local handle% = CreateFileW( file, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, Null, OPEN_EXISTING, 0, 0 )
    ASsert handle<>-1, "File does not exist"
    GetFileSizeEx( handle, Varptr out )
    CloseHandle( handle )
   
    ?Linux
    If stat64( file, statbank.Buf( ) ) <> 0 Then Assert "Unable to get file stats"
    out = statBank.PeekLong( 44 )
   
    ?MacOS
    Assert "GetFileSize not implemented for this platform"
   
    ?
   
    Return out
End Function


Comments :


N(Posted 1+ years ago)

 Added an untested implementation for Linux.  Anyone got the balls to test it?


N(Posted 1+ years ago)

 New version for Linux.  Tested and works from what I can see.