Skip to content

[os] file read cause file position error under Windows #24217

@kbkpbot

Description

@kbkpbot

Describe the bug

When read from a file, and then use f.tell() get the location, it give wrong position under Windows.

Reproduction Steps

create a file,
file_pos.v

module main
import os

fn main() {
    mut file := os.open('./file_pos.v')!
    defer { file.close() }

        s1 := file.tell()!
        b1 := file.read_bytes(8)
        s2 := file.tell()!

        dump(s1)
        dump(s2)
        dump(b1)

}

run it under Linux/Windows, and give different results.

Expected Behavior

D:\v\bug\coff>.\file_pos.exe
[file_pos.v:12] s1: 0
[file_pos.v:13] s2: 8
[file_pos.v:14] b1: [109, 111, 100, 117, 108, 101, 32, 109]

Current Behavior

D:\v\bug\coff>.\file_pos.exe
[file_pos.v:12] s1: 0
[file_pos.v:13] s2: 262
[file_pos.v:14] b1: [109, 111, 100, 117, 108, 101, 32, 109]

Possible Solution

No response

Additional Information/Context

Linux version, give correct result:

$ ./file_pos
[file_pos.v:12] s1: 0
[file_pos.v:13] s2: 8
[file_pos.v:14] b1: [109, 111, 100, 117, 108, 101, 32, 109]

V version

V 0.4.10 c2e27ef.c2e27ef

Environment details (OS name and version, etc.)

V full version V 0.4.10 c2e27ef.c2e27ef
OS windows, Microsoft Windows 10 企业版 LTSC 19044 64 位
Processor 16 cpus, 64bit, little endian, AMD Ryzen 7 7840H with Radeon 780M Graphics
Memory 3.06GB/27.69GB
V executable D:\v\v\v\v.exe
V last modified time 2025-04-13 08:24:19
V home dir OK, value: D:\v\v\v
VMODULES OK, value: C:\Users\DDT.vmodules
VTMP OK, value: C:\Users\DDT\AppData\Local\Temp\v_0
Current working dir OK, value: D:\v\v\v\thirdparty
Git version git version 2.43.0.windows.1
V git status weekly.2025.14-35-gc2e27ef2-dirty (10 commit(s) behind V master)
.git/config present true
cc version N/A
gcc version N/A
clang version N/A
msvc version 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.39.33523 版
tcc version tcc version 0.9.28rc 2024-12-30_mob@68000c01* (x86_64 Windows)
tcc git status N/A
emcc version N/A
glibc version N/A

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.OS: WindowsBugs/feature requests, that are specific to Windows OS.os.FileBugs related to the os.File implementation

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions