December 03, 2020, 08:48:12 PM

Author Topic: [bmx] Long Filesize by N [ 1+ years ago ]  (Read 465 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] Long Filesize by N [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
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
  1. ?Win32
  2. Const FILE_READ_ATTRIBUTES% = $00000080
  3. Const FILE_SHARE_READ% = $00000001
  4. Const OPEN_EXISTING% = 3
  5.  
  6. Extern "OS"
  7.     Function GetFileSizeEx:Int( handle%, size:Long Ptr )
  8.     Function CreateFileW:Int( filename$W, daccess%, sharem%, seca@ Ptr, cDisp%, flags%, template% )
  9.     Function CloseHandle:Int( handle% )
  10. End Extern
  11.  
  12. ?Linux
  13. Private
  14. Global statbank:TBank = TBank.Create(256) ' Maximum possible size
  15. Public
  16.  
  17. Extern "OS"
  18.     Function stat64:Int( path$z, buf@ Ptr )
  19. End Extern
  20.  
  21. ?MacOS
  22.  
  23. ?
  24.  
  25. Function GetFileSize:Long( file$ )
  26.     Local out:Long=-1
  27.    
  28.     ?Win32
  29.     Local handle% = CreateFileW( file, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, Null, OPEN_EXISTING, 0, 0 )
  30.     ASsert handle<>-1, "File does not exist"
  31.     GetFileSizeEx( handle, Varptr out )
  32.     CloseHandle( handle )
  33.    
  34.     ?Linux
  35.     If stat64( file, statbank.Buf( ) ) <> 0 Then Assert "Unable to get file stats"
  36.     out = statBank.PeekLong( 44 )
  37.    
  38.     ?MacOS
  39.     Assert "GetFileSize not implemented for this platform"
  40.    
  41.     ?
  42.    
  43.     Return out
  44. 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.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal