{"slug": "bstring", "name": "bstring", "category": "dev-libs", "category_name": "Libraries and frameworks", "description": "", "recommenders": 3, "commenters": 3, "warners": 0, "score": 2.474, "rising": -0.98, "first": "2025-12-30", "latest": "2025-12-30", "why": "After years I now think it's essential to have a library which records at least how much memory", "why_is_quote": true, "has_verdict": false, "sentiment": {"recommend": 3, "neutral": 0, "compare": 0, "warn": 0}, "spark": [0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "listed": true, "loved": [], "caveat": "", "short_quote": "After years I now think it's essential to have a library which records at least how much memory", "kind": "", "icon": false, "domain": null, "github_repo": "github.com/msteinert/bstring", "official_url": "https://github.com/msteinert/bstring", "pricing": "", "aliases": ["bstring"], "verdict": null, "praise": [{"label": "", "summary": "", "quotes": [{"id": 742939936, "item_id": 46433746, "url": "https://news.ycombinator.com/item?id=46433746", "by": "t43562", "date": "2025-12-30", "version": null, "stance": "recommend", "quote": "After years I now think it's essential to have a library which records at least how much memory", "excerpt": "I've always wondered at the motivatons of the various string routines in C - every one of them seems to have some huge caveat which makes them useless. After years I now think it's essential to have a library which records at least how much memory is allocated to a string along with the pointer. Something like this: https://github.com/msteinert/bstring", "context": "", "use_case": "", "switched_from": "", "story": "No strcpy either"}]}], "caveats": [], "who": [], "tags": [], "use_cases": ["c string library"], "compared": [], "makers": [], "threads": [{"url": "https://news.ycombinator.com/item?id=46433029", "title": "No strcpy either", "mentions": 3}], "sentiment_by_month": {"2025-11": {}, "2025-12": {"recommend": 3}, "2026-01": {}, "2026-02": {}, "2026-03": {}, "2026-04": {}, "2026-05": {}, "2026-06": {}, "2026-07": {}, "2026-08": {}, "2026-09": {}, "2026-10": {}}, "versions": [], "version_unnamed": 0, "family_ref": null, "runs_on": null, "lines": [], "quotes": [{"id": 742973056, "item_id": 46435816, "url": "https://news.ycombinator.com/item?id=46435816", "by": "Someone", "date": "2025-12-30", "version": null, "stance": "recommend", "quote": "", "excerpt": "> I've always wondered at the motivatons of the various string routines in C This idiom: char hostname[20]; ... strncpy( hostname, input, 20 ); hostname[19]=0; exists because strncpy was invented for copying file names that got stored in 14-byte arrays, zero terminated only if space permitted (https://stackoverflow.com/a/1454071)", "context": "", "use_case": "", "switched_from": "", "story": "No strcpy either"}, {"id": 742941856, "item_id": 46433866, "url": "https://news.ycombinator.com/item?id=46433866", "by": "formerly_proven", "date": "2025-12-30", "version": null, "stance": "recommend", "quote": "", "excerpt": "strncpy is fairly easy, that's a special-purpose function for copying a C string into a fixed-width string, like typically used in old C applications for on-disk formats. E.g. you might have a char username[20] field which can contain up to 20 characters, with unused characters filled with NULs. That's what strncpy is for. The destination argument should always be a fixed-size char array. A couple years ago we got a ", "context": "", "use_case": "C string library", "switched_from": "", "story": "No strcpy either"}, {"id": 742939936, "item_id": 46433746, "url": "https://news.ycombinator.com/item?id=46433746", "by": "t43562", "date": "2025-12-30", "version": null, "stance": "recommend", "quote": "After years I now think it's essential to have a library which records at least how much memory", "excerpt": "I've always wondered at the motivatons of the various string routines in C - every one of them seems to have some huge caveat which makes them useless. After years I now think it's essential to have a library which records at least how much memory is allocated to a string along with the pointer. Something like this: https://github.com/msteinert/bstring", "context": "", "use_case": "", "switched_from": "", "story": "No strcpy either"}]}