Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I ran into sprintf's dependence on locale recently when trying to use it in a WebAssembly module. Since I was compiling for the browser, I wanted to not depend on locale. Even setting aside the locale stuff, the wasi sdk still wanted to pull in file-related things like read/write/seek. I just wanted to do formatted print to a pre-existing buffer.

I ended up using nanoprintf — it's a single header file and in the public domain.

(https://github.com/charlesnicholson/nanoprintf)



P.S.: musl's sprintf is the one that I noticed pulling in file APIs, via vfprintf. Maybe other libc's implement sprintf without using the file API.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: