1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
//! # LOF Function
//!
//! Returns a Long representing the size, in bytes, of a file opened using the Open statement.
//!
//! ## Syntax
//!
//! ```vb
//! LOF(filenumber)
//! ```
//!
//! ## Parameters
//!
//! - `filenumber` (Required): Integer file number used in the Open statement
//! - Must be a valid file number from a currently open file
//! - File numbers typically obtained from `FreeFile` function
//! - Must be between 1 and 511
//!
//! ## Return Value
//!
//! Returns a Long:
//! - Size of the file in bytes
//! - For files opened in any mode (Binary, Random, Input, Output, Append)
//! - Returns 0 for empty files
//! - Maximum value 2,147,483,647 (Long type limit ~2GB)
//! - Returns actual file size on disk
//! - Updated immediately if file grows during operation
//!
//! ## Remarks
//!
//! The LOF function returns the length (size) of an open file:
//!
//! - Works with all file access modes (Binary, Random, Input, Output, Append)
//! - Returns size in bytes regardless of mode
//! - File must be open before calling LOF
//! - Does not change file pointer position
//! - Read-only operation (non-destructive)
//! - Useful for calculating progress during file operations
//! - Essential for determining number of records in Random files
//! - Used to allocate buffers for reading entire file
//! - Can be used with Loc to calculate percentage complete
//! - Error 52 "Bad file name or number" if file not open
//! - Error 68 "Device unavailable" if device unavailable
//! - For Random files, divide by record length to get record count
//! - Returns current size, even if file is being written to
//! - More reliable than `FileLen` for open files
//! - `FileLen` works on closed files, LOF works on open files
//! - Common in loops reading files to completion
//! - Used to detect empty files (LOF returns 0)
//! - Essential for progress bars and status indicators
//! - Helps prevent reading past end of file
//!
//! ## Typical Uses
//!
//! 1. **Get File Size**
//! ```vb
//! fileSize = LOF(1)
//! ```
//!
//! 2. **Calculate Record Count**
//! ```vb
//! recordCount = LOF(fileNum) / Len(record)
//! ```
//!
//! 3. **Read Entire File**
//! ```vb
//! buffer = String(LOF(fileNum), 0)
//! Get #fileNum, , buffer
//! ```
//!
//! 4. **Progress Calculation**
//! ```vb
//! percent = (Loc(fileNum) / LOF(fileNum)) * 100
//! ```
//!
//! 5. **Check Empty File**
//! ```vb
//! If LOF(fileNum) = 0 Then
//! MsgBox "File is empty"
//! End If
//! ```
//!
//! 6. **Loop Until End**
//! ```vb
//! Do While Loc(fileNum) < LOF(fileNum)
//! Get #fileNum, , data
//! Loop
//! ```
//!
//! 7. **Display File Size**
//! ```vb
//! lblSize.Caption = "Size: " & LOF(fileNum) & " bytes"
//! ```
//!
//! 8. **Allocate Byte Array**
//! ```vb
//! ReDim fileData(1 To LOF(fileNum)) As Byte
//! ```
//!
//! ## Basic Examples
//!
//! ### Example 1: Get File Size
//! ```vb
//! Dim fileNum As Integer
//! Dim fileSize As Long
//!
//! fileNum = FreeFile
//! Open "data.bin" For Binary As #fileNum
//!
//! fileSize = LOF(fileNum)
//! MsgBox "File size: " & fileSize & " bytes"
//!
//! Close #fileNum
//! ```
//!
//! ### Example 2: Calculate Record Count
//! ```vb
//! Type CustomerRecord
//! ID As Long
//! Name As String * 50
//! Balance As Currency
//! End Type
//!
//! Dim customer As CustomerRecord
//! Dim fileNum As Integer
//! Dim totalRecords As Long
//!
//! fileNum = FreeFile
//! Open "customers.dat" For Random As #fileNum Len = Len(customer)
//!
//! totalRecords = LOF(fileNum) / Len(customer)
//! MsgBox "Total customers: " & totalRecords
//!
//! Close #fileNum
//! ```
//!
//! ### Example 3: Read Entire File
//! ```vb
//! Dim fileNum As Integer
//! Dim fileContents As String
//! Dim fileSize As Long
//!
//! fileNum = FreeFile
//! Open "readme.txt" For Binary As #fileNum
//!
//! fileSize = LOF(fileNum)
//! fileContents = String(fileSize, 0)
//! Get #fileNum, , fileContents
//!
//! Close #fileNum
//!
//! MsgBox fileContents
//! ```
//!
//! ### Example 4: Progress Indicator
//! ```vb
//! Dim fileNum As Integer
//! Dim data As Byte
//! Dim fileSize As Long
//! Dim bytesRead As Long
//!
//! fileNum = FreeFile
//! Open "large.dat" For Binary As #fileNum
//! fileSize = LOF(fileNum)
//!
//! Do While Loc(fileNum) < fileSize
//! Get #fileNum, , data
//! ProcessByte data
//!
//! bytesRead = Loc(fileNum)
//! If bytesRead Mod 1024 = 0 Then
//! lblProgress.Caption = Format((bytesRead / fileSize) * 100, "0.0") & "%"
//! DoEvents
//! End If
//! Loop
//!
//! Close #fileNum
//! ```
//!
//! ## Common Patterns
//!
//! ### Pattern 1: `GetFileSize`
//! ```vb
//! Function GetFileSize(ByVal fileNum As Integer) As Long
//! On Error Resume Next
//! GetFileSize = LOF(fileNum)
//! If Err.Number <> 0 Then
//! GetFileSize = -1
//! Err.Clear
//! End If
//! End Function
//! ```
//!
//! ### Pattern 2: `CalculateRecordCount`
//! ```vb
//! Function CalculateRecordCount(ByVal fileNum As Integer, _
//! ByVal recordLength As Long) As Long
//! Dim fileSize As Long
//! fileSize = LOF(fileNum)
//!
//! If recordLength > 0 Then
//! CalculateRecordCount = fileSize \ recordLength
//! Else
//! CalculateRecordCount = 0
//! End If
//! End Function
//! ```
//!
//! ### Pattern 3: `ReadEntireFile`
//! ```vb
//! Function ReadEntireFile(ByVal fileNum As Integer) As String
//! Dim fileSize As Long
//! Dim buffer As String
//!
//! fileSize = LOF(fileNum)
//! If fileSize > 0 Then
//! buffer = String(fileSize, 0)
//! Get #fileNum, 1, buffer
//! ReadEntireFile = buffer
//! Else
//! ReadEntireFile = ""
//! End If
//! End Function
//! ```
//!
//! ### Pattern 4: `ReadEntireFileAsBytes`
//! ```vb
//! Function ReadEntireFileAsBytes(ByVal fileNum As Integer) As Byte()
//! Dim fileSize As Long
//! Dim buffer() As Byte
//!
//! fileSize = LOF(fileNum)
//! If fileSize > 0 Then
//! ReDim buffer(0 To fileSize - 1) As Byte
//! Get #fileNum, 1, buffer
//! ReadEntireFileAsBytes = buffer
//! End If
//! End Function
//! ```
//!
//! ### Pattern 5: `CalculateProgress`
//! ```vb
//! Function CalculateProgress(ByVal fileNum As Integer) As Single
//! Dim currentPos As Long
//! Dim totalSize As Long
//!
//! currentPos = Loc(fileNum)
//! totalSize = LOF(fileNum)
//!
//! If totalSize > 0 Then
//! CalculateProgress = (currentPos / totalSize) * 100
//! Else
//! CalculateProgress = 0
//! End If
//! End Function
//! ```
//!
//! ### Pattern 6: `IsEmptyFile`
//! ```vb
//! Function IsEmptyFile(ByVal fileNum As Integer) As Boolean
//! IsEmptyFile = (LOF(fileNum) = 0)
//! End Function
//! ```
//!
//! ### Pattern 7: `GetBytesRemaining`
//! ```vb
//! Function GetBytesRemaining(ByVal fileNum As Integer) As Long
//! GetBytesRemaining = LOF(fileNum) - Loc(fileNum)
//! End Function
//! ```
//!
//! ### Pattern 8: `FormatFileSize`
//! ```vb
//! Function FormatFileSize(ByVal fileNum As Integer) As String
//! Dim bytes As Long
//! bytes = LOF(fileNum)
//!
//! If bytes < 1024 Then
//! FormatFileSize = bytes & " bytes"
//! ElseIf bytes < 1048576 Then
//! FormatFileSize = Format(bytes / 1024, "0.0") & " KB"
//! Else
//! FormatFileSize = Format(bytes / 1048576, "0.0") & " MB"
//! End If
//! End Function
//! ```
//!
//! ### Pattern 9: `IsAtEndOfFile`
//! ```vb
//! Function IsAtEndOfFile(ByVal fileNum As Integer) As Boolean
//! IsAtEndOfFile = (Loc(fileNum) >= LOF(fileNum))
//! End Function
//! ```
//!
//! ### Pattern 10: `AllocateBuffer`
//! ```vb
//! Function AllocateBuffer(ByVal fileNum As Integer) As String
//! Dim size As Long
//! size = LOF(fileNum)
//!
//! If size > 0 Then
//! AllocateBuffer = String(size, 0)
//! Else
//! AllocateBuffer = ""
//! End If
//! End Function
//! ```
//!
//! ## Advanced Examples
//!
//! ### Example 1: File Reader Class
//! ```vb
//! ' Class: FileReader
//! Private m_fileNum As Integer
//! Private m_filename As String
//! Private m_fileSize As Long
//! Private m_isOpen As Boolean
//!
//! Public Sub OpenFile(ByVal filename As String)
//! If m_isOpen Then CloseFile
//!
//! m_filename = filename
//! m_fileNum = FreeFile
//! Open filename For Binary As #m_fileNum
//! m_fileSize = LOF(m_fileNum)
//! m_isOpen = True
//! End Sub
//!
//! Public Property Get Size() As Long
//! If m_isOpen Then
//! Size = m_fileSize
//! Else
//! Size = 0
//! End If
//! End Property
//!
//! Public Property Get Position() As Long
//! If m_isOpen Then
//! Position = Loc(m_fileNum)
//! Else
//! Position = 0
//! End If
//! End Property
//!
//! Public Property Get Progress() As Single
//! If m_isOpen And m_fileSize > 0 Then
//! Progress = (Loc(m_fileNum) / m_fileSize) * 100
//! Else
//! Progress = 0
//! End If
//! End Property
//!
//! Public Property Get IsEOF() As Boolean
//! If m_isOpen Then
//! IsEOF = (Loc(m_fileNum) >= m_fileSize)
//! Else
//! IsEOF = True
//! End If
//! End Property
//!
//! Public Property Get IsEmpty() As Boolean
//! IsEmpty = (m_fileSize = 0)
//! End Property
//!
//! Public Function ReadAll() As String
//! If m_isOpen And m_fileSize > 0 Then
//! ReadAll = String(m_fileSize, 0)
//! Get #m_fileNum, 1, ReadAll
//! Else
//! ReadAll = ""
//! End If
//! End Function
//!
//! Public Sub CloseFile()
//! If m_isOpen Then
//! Close #m_fileNum
//! m_isOpen = False
//! m_fileSize = 0
//! End If
//! End Sub
//!
//! Private Sub Class_Terminate()
//! CloseFile
//! End Sub
//! ```
//!
//! ### Example 2: Random File Manager
//! ```vb
//! ' Class: RandomFileManager
//! Private m_fileNum As Integer
//! Private m_recordLength As Long
//! Private m_totalRecords As Long
//! Private m_isOpen As Boolean
//!
//! Public Sub OpenFile(ByVal filename As String, _
//! ByVal recordLength As Long)
//! If m_isOpen Then CloseFile
//!
//! m_recordLength = recordLength
//! m_fileNum = FreeFile
//! Open filename For Random As #m_fileNum Len = recordLength
//!
//! m_totalRecords = LOF(m_fileNum) \ recordLength
//! m_isOpen = True
//! End Sub
//!
//! Public Property Get RecordCount() As Long
//! If m_isOpen Then
//! RecordCount = m_totalRecords
//! Else
//! RecordCount = 0
//! End If
//! End Property
//!
//! Public Property Get FileSize() As Long
//! If m_isOpen Then
//! FileSize = LOF(m_fileNum)
//! Else
//! FileSize = 0
//! End If
//! End Property
//!
//! Public Property Get CurrentRecord() As Long
//! If m_isOpen Then
//! CurrentRecord = Loc(m_fileNum)
//! Else
//! CurrentRecord = 0
//! End If
//! End Property
//!
//! Public Function IsValidRecord(ByVal recordNum As Long) As Boolean
//! IsValidRecord = (recordNum >= 1 And recordNum <= m_totalRecords)
//! End Function
//!
//! Public Sub RefreshRecordCount()
//! If m_isOpen Then
//! m_totalRecords = LOF(m_fileNum) \ m_recordLength
//! End If
//! End Sub
//!
//! Public Sub CloseFile()
//! If m_isOpen Then
//! Close #m_fileNum
//! m_isOpen = False
//! m_totalRecords = 0
//! End If
//! End Sub
//!
//! Private Sub Class_Terminate()
//! CloseFile
//! End Sub
//! ```
//!
//! ### Example 3: File Copy with Progress
//! ```vb
//! Sub CopyFileWithProgress(ByVal sourceFile As String, _
//! ByVal destFile As String, _
//! Optional ByVal progressBar As ProgressBar = Nothing)
//! Dim sourceNum As Integer, destNum As Integer
//! Dim buffer(1 To 4096) As Byte
//! Dim bytesRead As Long
//! Dim totalSize As Long
//! Dim lastPercent As Integer
//! Dim currentPercent As Integer
//!
//! ' Open source file
//! sourceNum = FreeFile
//! Open sourceFile For Binary As #sourceNum
//! totalSize = LOF(sourceNum)
//!
//! ' Open destination file
//! destNum = FreeFile
//! Open destFile For Binary As #destNum
//!
//! ' Copy in chunks
//! Do While Loc(sourceNum) < totalSize
//! Get #sourceNum, , buffer
//! Put #destNum, , buffer
//!
//! If Not progressBar Is Nothing Then
//! bytesRead = Loc(sourceNum)
//! currentPercent = Int((bytesRead / totalSize) * 100)
//!
//! If currentPercent <> lastPercent Then
//! progressBar.Value = currentPercent
//! lastPercent = currentPercent
//! DoEvents
//! End If
//! End If
//! Loop
//!
//! Close #sourceNum
//! Close #destNum
//! End Sub
//! ```
//!
//! ### Example 4: File Information Display
//! ```vb
//! ' Form with labels and progress bar
//! Private m_fileNum As Integer
//! Private m_fileSize As Long
//!
//! Private Sub OpenAndDisplayFile(ByVal filename As String)
//! m_fileNum = FreeFile
//! Open filename For Binary As #m_fileNum
//! m_fileSize = LOF(m_fileNum)
//!
//! ' Display file information
//! lblFilename.Caption = filename
//! lblFileSize.Caption = FormatBytes(m_fileSize)
//! ProgressBar1.Min = 0
//! ProgressBar1.Max = 100
//!
//! Timer1.Enabled = True
//! End Sub
//!
//! Private Sub ProcessFile()
//! Dim data As Byte
//!
//! Do While Loc(m_fileNum) < m_fileSize
//! Get #m_fileNum, , data
//! ProcessByte data
//! Loop
//!
//! Timer1.Enabled = False
//! Close #m_fileNum
//! MsgBox "Processing complete!"
//! End Sub
//!
//! Private Sub Timer1_Timer()
//! UpdateProgress
//! End Sub
//!
//! Private Sub UpdateProgress()
//! Dim bytesProcessed As Long
//! Dim percent As Single
//!
//! On Error Resume Next
//! bytesProcessed = Loc(m_fileNum)
//!
//! If m_fileSize > 0 Then
//! percent = (bytesProcessed / m_fileSize) * 100
//! ProgressBar1.Value = percent
//!
//! lblProgress.Caption = FormatBytes(bytesProcessed) & " of " & _
//! FormatBytes(m_fileSize) & " (" & _
//! Format(percent, "0.0") & "%)"
//! End If
//! End Sub
//!
//! Private Function FormatBytes(ByVal bytes As Long) As String
//! If bytes < 1024 Then
//! FormatBytes = bytes & " B"
//! ElseIf bytes < 1048576 Then
//! FormatBytes = Format(bytes / 1024, "0.0") & " KB"
//! ElseIf bytes < 1073741824 Then
//! FormatBytes = Format(bytes / 1048576, "0.0") & " MB"
//! Else
//! FormatBytes = Format(bytes / 1073741824, "0.0") & " GB"
//! End If
//! End Function
//! ```
//!
//! ## Error Handling
//!
//! ```vb
//! ' Error 52: Bad file name or number
//! On Error Resume Next
//! size = LOF(999)
//! If Err.Number = 52 Then
//! MsgBox "File not open!"
//! End If
//!
//! ' Error 68: Device unavailable
//! size = LOF(fileNum)
//! If Err.Number = 68 Then
//! MsgBox "Device unavailable!"
//! End If
//!
//! ' Safe size retrieval
//! Function GetSafeFileSize(ByVal fileNum As Integer) As Long
//! On Error Resume Next
//! GetSafeFileSize = LOF(fileNum)
//! If Err.Number <> 0 Then
//! GetSafeFileSize = -1
//! Err.Clear
//! End If
//! End Function
//! ```
//!
//! ## Performance Considerations
//!
//! - **Very Fast**: LOF is a simple file system query
//! - **No I/O**: Does not read file contents
//! - **Cache Result**: Store in variable if using multiple times
//! - **No Side Effects**: Does not change file pointer
//! - **Constant Time**: O(1) operation regardless of file size
//!
//! ## Best Practices
//!
//! 1. **Cache the value** if using LOF multiple times in a loop
//! 2. **Check for zero** to detect empty files
//! 3. **Use for buffer allocation** when reading entire files
//! 4. **Combine with Loc** for progress calculation
//! 5. **Use integer division** (\\) for record count calculation
//! 6. **Handle errors** for unopened files
//! 7. **Check 2GB limit** for very large files
//! 8. **Refresh if writing** as file size may change
//! 9. **Use with Random files** to calculate record count
//! 10. **Prefer over `FileLen`** for open files
//!
//! ## Comparison with Related Functions
//!
//! | Function | Purpose | File State | Return Value |
//! |----------|---------|------------|--------------|
//! | **LOF** | Get file size | Must be open | Size in bytes |
//! | **`FileLen`** | Get file size | Must be closed | Size in bytes |
//! | **Loc** | Get position | Must be open | Current position |
//! | **Seek** | Get/set position | Must be open | Next position |
//! | **EOF** | Check end | Must be open | Boolean |
//!
//! ## LOF vs `FileLen`
//!
//! ```vb
//! ' FileLen - for closed files
//! size = FileLen("data.dat")
//!
//! ' LOF - for open files
//! Open "data.dat" For Binary As #1
//! size = LOF(1)
//! Close #1
//!
//! ' LOF is better for open files:
//! ' - Reflects current size if file is being written
//! ' - Faster (no need to close and reopen)
//! ' - Works with all file modes
//! ```
//!
//! ## Mode-Specific Usage
//!
//! ```vb
//! ' Binary mode - get exact byte count
//! Open "data.bin" For Binary As #1
//! totalBytes = LOF(1)
//!
//! ' Random mode - calculate record count
//! Open "records.dat" For Random As #1 Len = 128
//! totalRecords = LOF(1) \ 128
//!
//! ' Input mode - get file size for progress
//! Open "text.txt" For Input As #1
//! fileSize = LOF(1)
//!
//! ' Output/Append mode - check current size
//! Open "log.txt" For Append As #1
//! currentSize = LOF(1)
//! ```
//!
//! ## Platform Notes
//!
//! - Available in all VB6 versions
//! - Part of VBA core library
//! - Returns Long (max ~2GB file support)
//! - For files > 2GB, result may overflow (wraps to negative)
//! - Windows-specific file I/O
//! - Behavior identical across Windows versions
//! - Works with local and network files
//! - UNC paths supported
//!
//! ## Limitations
//!
//! - **2GB Limit**: Long type limits to ~2,147,483,647 bytes
//! - **Files > 2GB**: Result overflows and becomes negative
//! - **Requires Open File**: Error 52 if file not open
//! - **No String Files**: Works with file numbers only
//! - **Not for Directories**: Only for files
//! - **Static at Call**: Returns size at moment of call
//! - **No Metadata**: Only returns size, not other attributes
//!
//! ## Related Functions
//!
//! - `Loc`: Get current read/write position in file
//! - `Seek`: Get/set file position
//! - `EOF`: Check if at end of file
//! - `FileLen`: Get length of closed file
//! - `Open`: Open file for I/O
//! - `Close`: Close open file
//! - `FreeFile`: Get available file number
//! - `FileAttr`: Get file mode or handle
use crate;
use crate;
use crate;
/// Get the length of an open file in bytes.
///
/// # Arguments
///
/// * `file_number` - The file number.
///
/// # Returns
///
/// Returns the file length in bytes, or 0 if the file is not open.