Skip to content

Replace libc functions with WinAPIs on Windows #20861

Closed
@klutzy

Description

@klutzy

We use libc functions on various Windows routines, but they are just convenient wrappers of WinAPI and there's usually no critical reason to use them.

Also, the wrapper has its own runtime state so it adds additional complexity, so it's better to use WinAPI than libc functions in general.
For example, msvcrt has libc errno variable, but it's not Windows' native error code value (GetLastError()) therefore unrelated to std::os::errno().
Another example is that msvcrt manages its own "C locale", distinct to Windows locale.

Here's some libc uses (not complete):

  • rt/rust_builtin.c: e.g. gmtime, localtime. (seems like they are unused now)
  • liballoc/heap.rs uses malloc, realloc, free if jemalloc is disabled. HeapAlloc is better?
  • libstd/sys/windows/: e.g. fs.rs uses open_osfhandle.

See also Support: Win32 Equivalents for C Run-Time Functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions