frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

How to Use Snprintf

https://bernsteinbear.com/blog/snprintf/
20•surprisetalk•2d ago

Comments

hdjrudni•2d ago
This sentence is confusing:

> I have size_with_nul because snprintf man pages say

> The functions snprintf() and vsnprintf() write at most size bytes (including the terminating null byte (‘\0’)) to str.

If 'size' includes the null byte, why do we have to add 1?

king_geedorah•2d ago
> If the output was truncated due to this limit, then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available.

The initial call with size 0 tells you the necessary length of the buffer for the string you want, but does not include the null byte.

orbisvicis•58m ago
For clarity, all snprintf calls "return the number of bytes that would be written to s had n been sufficiently large excluding the terminating null byte" [1].

1. https://man7.org/linux/man-pages/man3/fprintf.3p.html

chrsw•11m ago
The first sentence is confusing for me.
st_goliath•48m ago
There are `asprintf` and `vasprintf` (takes a va_list argument). Those allocate a sufficiently sized buffer that can be released with `free`.

Yes, it's a GNU extension, but it's also supported by various BSDs [1][2][3], and yes, Musl has it too. It's present in pretty much any sane C library.

[1] https://man.openbsd.org/man3/printf.3

[2] https://man.netbsd.org/vasprintf.3

[3] https://man.freebsd.org/cgi/man.cgi?query=vasprintf&sektion=...

rwmj•32m ago
And combine it with __attribute__((cleanup)) to get the string automatically freed at the end of your function (if that's the right thing to do). Looks like cleanup with be standardized finally in the next C2x.
RhysU•44m ago
Once I hacked up an snprintf wrapper that automated any required realloc calls:

https://github.com/RhysU/snprintf_realloc/blob/master/snprin...

Worth critically reviewing before using. It's been a while.

Custom telescope mount using harmonic drives and ESP32

https://www.svendewaerhert.com/blog/telescope-mount/
42•waerhert•1h ago•3 comments

Prime Number Grid

https://susam.net/primegrid.html
138•todsacerdoti•4h ago•52 comments

Google is killing the open web

https://wok.oblomov.eu/tecnologia/google-killing-open-web/
43•thm•2h ago•24 comments

Lazy-brush – smooth drawing with mouse or finger

https://lazybrush.dulnan.net
272•tvdvd•3d ago•38 comments

OpenMower – An open source lawn mower

https://github.com/ClemensElflein/OpenMower
355•rickcarlino•11h ago•83 comments

In 2006, Hitachi developed a 0.15mm-sized RFID chip

https://www.hitachi.com/New/cnews/060206.html
11•julkali•3d ago•4 comments

How to Build a Medieval Castle

https://archaeology.org/issues/september-october-2025/features/how-to-build-a-medieval-castle/
87•benbreen•6h ago•13 comments

Netflix Revamps Tudum's CQRS Architecture with Raw Hollow In-Memory Object Store

https://www.infoq.com/news/2025/08/netflix-tudum-cqrs-raw-hollow/
35•NomDePlum•2d ago•24 comments

Show HN: Whispering – Open-source, local-first dictation you can trust

https://github.com/epicenter-so/epicenter/tree/main/apps/whispering
424•braden-w•18h ago•121 comments

Tiny-tpu: A minimal tensor processing unit (TPU), inspired by Google's TPU

https://github.com/tiny-tpu-v2/tiny-tpu
207•admp•15h ago•6 comments

X-ray scans reveal Buddhist prayers inside tiny Tibetan scrolls

https://www.popsci.com/technology/tibetan-prayer-scroll-scans/
129•Hooke•2d ago•41 comments

Counter-Strike: A billion-dollar game built in a dorm room

https://www.nytimes.com/2025/08/18/arts/counter-strike-half-life-minh-le.html
383•asnyder•20h ago•317 comments

Show HN: I built an app to block Shorts and Reels

https://scrollguard.app/
601•adrianhacar•2d ago•249 comments

Ted Chiang: The Secret Third Thing

https://linch.substack.com/p/ted-chiang-review
140•pseudolus•11h ago•66 comments

Obsidian Bases

https://help.obsidian.md/bases
552•twapi•14h ago•179 comments

Left to Right Programming

https://graic.net/p/left-to-right-programming
347•graic•18h ago•279 comments

The Life and Death of London's Crystal Palace (2021)

https://heritagecalling.com/2021/11/29/picturing-the-crystal-palace/
15•zeristor•4d ago•6 comments

FFmpeg Assembly Language Lessons

https://github.com/FFmpeg/asm-lessons
382•flykespice•22h ago•123 comments

Walkie-Textie Wireless Communicator

http://www.technoblogy.com/show?2AON
156•chrisjj•2d ago•97 comments

Electromechanical reshaping, an alternative to laser eye surgery

https://medicalxpress.com/news/2025-08-alternative-lasik-lasers.html
262•Gaishan•1d ago•112 comments

Show HN: We started building an AI dev tool but it turned into a Sims-style game

https://www.youtube.com/watch?v=sRPnX_f2V_c
127•maxraven•16h ago•65 comments

How to Use Snprintf

https://bernsteinbear.com/blog/snprintf/
20•surprisetalk•2d ago•7 comments

Croatian freediver held breath for 29 minutes

https://divernet.com/scuba-news/freediving/how-croatian-freediver-held-breath-for-29-minutes/
238•toomanyrichies•11h ago•108 comments

An IRC-Enabled Lawn Mower (2021)

https://jotunheimr.idlerpg.net/users/jotun/lawnmower/
101•rickcarlino•2d ago•20 comments

Anna's Archive: An Update from the Team

https://annas-archive.org/blog/an-update-from-the-team.html
961•jerheinze•19h ago•454 comments

Newgrounds: Flash Forward 2025

https://www.newgrounds.com/bbs/topic/1542140
84•lsferreira42•13h ago•29 comments

Spice Data (YC S19) Is Hiring a Product Associate (New Grad)

https://www.ycombinator.com/companies/spice-data/jobs/RJz1peY-product-associate-new-grad
1•richard_pepper•14h ago

The rising returns to R&D: Ideas are not getting harder to find

https://papers.ssrn.com/sol3/papers.cfm?abstract_id=5242171
106•surprisetalk•4d ago•41 comments

Launch HN: Reality Defender (YC W22) – API for Deepfake and GenAI Detection

https://www.realitydefender.com/platform/api
85•bpcrd•20h ago•43 comments

Association for the Preservation of Spiritualist and Occult Periodicals

https://iapsop.com
36•andrii•3d ago•4 comments