os._win32
Windows backend for os; native little-endian Windows x64/ARM64 only.
All foreign declarations are local to functions and nothing calls Windows at
module initialization. The public os module supplies compile-time dispatch and
the environ mapping. This module does not import os or port the compiler/runtime.
Called functions require Kernel32 and a compatible Microsoft UCRT;
no new C++ runtime helpers are needed.
Paths, commands and environment use UTF-16LE with surrogatepass, never ANSI.
getcwdb() uses UTF-8 with surrogatepass, as modern Python on Windows does. Extended-length
paths are accepted as supplied; no automatic long-path prefix/manifest is added.
mkdir() ignores mode and inherits the parent's Windows security descriptor (even
for 0o700); chmod() changes only the read-only attribute. access() is an attribute
probe, not an ACL check, and X_OK means existence. Descriptor I/O retains the
descriptor's CRT text/binary mode and can return partial transfers.
Environment updates are not atomic across the CRT and OS and must be externally
synchronized with other environment writers. The CRT treats an empty value as
deletion; putenv() restores an actual empty OS value afterwards, but cannot make
CRT getenv() distinguish empty from missing. Other CRT instances/ANSI mirrors
cannot be kept fully Unicode-consistent. No snapshot is updated here.
OSError carries errno, strerror, applicable filenames and the original winerror
for Windows API failures. CRT failures supply errno without inventing winerror.
Toolhelp reports the recorded parent PID, which can have exited or been reused.
This backend has not been executed on Windows as part of its implementation.
stat(path: str, follow_symlinks: bool = True)
fstat(fd: int)
open(path: str, flags: int, mode: int = 0o777)
listdir(path: str = ".")
realpath(path: str, strict: bool = False)
make_env_map()
Return an uppercase-key snapshot of the actual Windows environment.
putenv(key: str, value: str)
Update CRT and OS environment, but not the public environ snapshot.
unsetenv(key: str)
process_getenv(key: str)
Query the true OS environment, distinguishing empty from missing.
system(cmd: str)
Run the Windows command processor; return its native status, not wait bits.
mkdir(path: str, mode: int = 0o777)
rmdir(path: str)
chdir(path: str)
getcwd()
getcwdb()
unlink(path: str)
remove(path: str)
rename(src: str, dst: str)
replace(src: str, dst: str)
link(src: str, dst: str)
symlink(src: str, dst: str, target_is_directory: bool = False)
readlink(path: str)
access(path: str, mode: int)
chmod(path: str, mode: int)
getpid()
getppid()
close(fd: int)
read(fd: int, n: int)
write(fd: int, data: bytes)
lseek(fd: int, pos: int, how: int)
fsync(fd: int)
ftruncate(fd: int, length: int)
truncate(path: str, length: int)
getfullpathname(path: str)
Resolve Windows drive-relative/UNC syntax without requiring existence.