Skip to content

Add sprintf, snprintf, and the scanf family for Windows#5024

Open
dropbear32 wants to merge 1 commit intorust-lang:mainfrom
dropbear32:main
Open

Add sprintf, snprintf, and the scanf family for Windows#5024
dropbear32 wants to merge 1 commit intorust-lang:mainfrom
dropbear32:main

Conversation

@dropbear32
Copy link
Copy Markdown

@dropbear32 dropbear32 commented Mar 19, 2026

Description

This adds declarations for the following functions for Windows:

  • sprintf
  • snprintf
  • scanf
  • sscanf
  • fscanf

As noted in #2860, these are provided by legacy_stdio_definitions.lib in newer versions of Windows, so they're behind the same gate.

This fixes #4995.

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget); especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Mar 19, 2026
@tgross35
Copy link
Copy Markdown
Contributor

The definitions look fine, but what is the story with legacy_stdio_definitions? I don't know if there's a reason users should be avoiding symbols that aren't in the ucrt, though I don't really understand why these wouldn't be in the ucrt in the first place.

Cc @ChrisDenton for thoughts here.

@dropbear32
Copy link
Copy Markdown
Author

dropbear32 commented Mar 19, 2026

For whatever reason, Microsoft moved to defining these inline in stdio.h: https://learn.microsoft.com/en-us/cpp/porting/visual-cpp-change-history-2003-2015#stdio_and_conio

They provide legacy_stdio_definitions.lib as a compatibility measure if you're not using the header that defines these functions.

@ChrisDenton
Copy link
Copy Markdown
Member

Yep, they're defined inline. We could potentially write our own wrappers around the internal versions but I've not investigated that and including legacy_stdio_definitions.lib is definitely the easier option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support sprintf/snprintf and sscanf on windows

4 participants