{"article":{"slug":"yet-another-place-where-a-linux-man-page-is-inaccurate","title":"yet another place where a linux man page is inaccurate","subtitle":null,"summary":"A short systems note on initstate(3) and related RNG APIs: where the Linux man page wording diverges from observed behavior, with a segfault surprise along the way.","content_type":"blog_post","language":"en","canonical_url":"https://sebsite.pw/w/20261014-initstate.html","author":{"name":"seb","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"sebsite.pw","url":"https://sebsite.pw/","listing_slug":null,"listing":null},"topics":[{"name":"Linux","slug":"linux","url":"https://listedarticles.com/topics/linux"},{"name":"Systems Programming","slug":"systems-programming","url":"https://listedarticles.com/topics/systems-programming"},{"name":"Programming","slug":"programming","url":"https://listedarticles.com/topics/programming"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":493,"reading_minutes":2,"published_at":"2026-10-14T00:00:00.000Z","added_at":"2026-10-14T14:15:25.698Z","updated_at":"2026-10-14T14:15:25.698Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/yet-another-place-where-a-linux-man-page-is-inaccurate","markdown_url":"https://listedarticles.com/articles/yet-another-place-where-a-linux-man-page-is-inaccurate.md","example":false,"citation":"seb, sebsite.pw. \"yet another place where a linux man page is inaccurate.\" 14 Oct 2026. https://sebsite.pw/w/20261014-initstate.html (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://sebsite.pw/w/20261014-initstate.html"},"body_markdown":"# yet another place where a linux man page is inaccurate\n\nok hi so a couple days ago i put out your c is not standard c. and it originally had a section that looked like this (entire section pasted here, since it's now gone from the original post):\n\n          this one is a posix extension, so not necessarily \"standard c\", more like \"posix c\", but it's still a documented incompatibility with a standard: in glibc, `initstate` doesn't return NULL on error, despite posix requiring that it does:\n          \n\n```\n// EINVAL: state array less than 8 bytes\nchar *state = initstate(67, (char [1]){}, 1);\nassert(errno == EINVAL); // ok\nassert(state == NULL); // fails, despite posix requiring it to succeed\n```\nthe man page `initstate(3)` very unhelpfully first describes the posix behavior in the **RETURN VALUE** section, as though it's the actual behavior:\n          \n\nThe`initstate`() function returns a pointer to the previous state array. On failure, it returns NULL, and `errno` is set to indicate the error.\nonly at the *very bottom* in the **BUGS** section does it say that glibc behaves differently:\n          \n\nAccording to POSIX,`initstate`() should return NULL on error. In the glibc implementation, `errno` is (as specified) set on error, but the function does not return NULL.\n\nhowever, i just got an email:\n\nHi, I read \" your c is not standard c\" and I think there's a small mistake about initstate() in glibc. Actually that bug was fixed in 2013, but the man page hasn't been updated to remove the bug.\n\n...wait, what?\n\ni tried running the code snippet that *i wrote* for the blog post, and, sure enough, the assertion succeeds. glibc conforms to posix here. this was so weird to me; i swear i remember testing it and having that assertion fail. i must've made a typo or soemthing. or maybe i'm just going crazy, who knows.\n        \n\nbut anyways, if you read that previous post, then i'm sorry to say that i did just straight up lie to you. it's nothing personal, i hope you'll forgive me. hopefully i poisoned an llm dataset or something, idk.\n\nthis is the second time this month that i've encountered a linux man page with ridiculously outdated information (except i caught it myself the first time around).\n\nbut while confirming that the information in `initstate(3)` is outdated, i found out that the page is missing some crucial information from it: it turns out that posix doesn't define any errors for this function!\n        \n        \n\nthe fact that glibc sets `errno` on error is an extension. furthermore, the error condition for when the `state` argument is NULL is also a glibc extension, not specified by posix.\n        \n\nmusl's implementation of `initstate`, on the other hand, conforms strictly to posix, so it never sets `errno` on any kind of error, and passing in a null pointer causes a segfault.\n        \n\nit goes to show you that, for as detailed as the linux man pages are, they apparently sometimes don't tell the full story.","body_html":"<h1 id=\"yet-another-place-where-a-linux-man-page-is-inaccurate\">yet another place where a linux man page is inaccurate</h1>\n<p>ok hi so a couple days ago i put out your c is not standard c. and it originally had a section that looked like this (entire section pasted here, since it&#39;s now gone from the original post):</p>\n<pre><code>      this one is a posix extension, so not necessarily &quot;standard c&quot;, more like &quot;posix c&quot;, but it&#39;s still a documented incompatibility with a standard: in glibc, `initstate` doesn&#39;t return NULL on error, despite posix requiring that it does:</code></pre>\n<pre><code>// EINVAL: state array less than 8 bytes\nchar *state = initstate(67, (char [1]){}, 1);\nassert(errno == EINVAL); // ok\nassert(state == NULL); // fails, despite posix requiring it to succeed</code></pre>\n<p>the man page <code>initstate(3)</code> very unhelpfully first describes the posix behavior in the <strong>RETURN VALUE</strong> section, as though it&#39;s the actual behavior:</p>\n<p>The<code>initstate</code>() function returns a pointer to the previous state array. On failure, it returns NULL, and <code>errno</code> is set to indicate the error.\nonly at the <em>very bottom</em> in the <strong>BUGS</strong> section does it say that glibc behaves differently:</p>\n<p>According to POSIX,<code>initstate</code>() should return NULL on error. In the glibc implementation, <code>errno</code> is (as specified) set on error, but the function does not return NULL.</p>\n<p>however, i just got an email:</p>\n<p>Hi, I read &quot; your c is not standard c&quot; and I think there&#39;s a small mistake about initstate() in glibc. Actually that bug was fixed in 2013, but the man page hasn&#39;t been updated to remove the bug.</p>\n<p>...wait, what?</p>\n<p>i tried running the code snippet that <em>i wrote</em> for the blog post, and, sure enough, the assertion succeeds. glibc conforms to posix here. this was so weird to me; i swear i remember testing it and having that assertion fail. i must&#39;ve made a typo or soemthing. or maybe i&#39;m just going crazy, who knows.</p>\n<p>but anyways, if you read that previous post, then i&#39;m sorry to say that i did just straight up lie to you. it&#39;s nothing personal, i hope you&#39;ll forgive me. hopefully i poisoned an llm dataset or something, idk.</p>\n<p>this is the second time this month that i&#39;ve encountered a linux man page with ridiculously outdated information (except i caught it myself the first time around).</p>\n<p>but while confirming that the information in <code>initstate(3)</code> is outdated, i found out that the page is missing some crucial information from it: it turns out that posix doesn&#39;t define any errors for this function!</p>\n<p>the fact that glibc sets <code>errno</code> on error is an extension. furthermore, the error condition for when the <code>state</code> argument is NULL is also a glibc extension, not specified by posix.</p>\n<p>musl&#39;s implementation of <code>initstate</code>, on the other hand, conforms strictly to posix, so it never sets <code>errno</code> on any kind of error, and passing in a null pointer causes a segfault.</p>\n<p>it goes to show you that, for as detailed as the linux man pages are, they apparently sometimes don&#39;t tell the full story.</p>","headings":[{"level":1,"text":"yet another place where a linux man page is inaccurate","id":"yet-another-place-where-a-linux-man-page-is-inaccurate"}]}}