Login
You're viewing the functional.cafe public feed.

Replies

  • Jun 28, 2026, 1:27 PM

    @Gottox Not once since I switched to musl 😝 (it uses "No error information" for errno code 0)

    But it really depends on what you're doing. It's rare that I have to report an error from user code; mostly I'm reporting errors from system calls, which always set errno.
    It's just a habit to have, I don't find it more or less fragile than anything else.

    💬 1🔄 0⭐ 0
  • Jun 28, 2026, 1:36 PM
    @ska @Gottox i find it awkward when i have my own error types

    so i either need to wrap every possible syscall errno into them, or have a LIBFOO_ERROR_SYSTEM as say "when a system error is returned, check errno" which feels... awkward? but maybe it's fine
    💬 2🔄 0⭐ 0
  • Jun 28, 2026, 1:41 PM

    @navi @Gottox yeah at low levels errno is good; at higher levels I sometimes use errno as well when the codes map relatively well to the semantics I want. Sometimes it's just not possible, in which case I need to define specific error codes, but this is annoying to do and even more annoying to document; I try to avoid that out of sheer laziness.

    Note that LIBFOO_ERROR_SYSTEM is exactly what getaddrinfo() does: it has an EAI_SYSTEM error value. I think it's fine for this kind of function; impractical, yes, but about the best you can do.

    💬 0🔄 0⭐ 0
  • 💬 0🔄 0⭐ 0
  • Jun 28, 2026, 7:27 PM

    @Gottox @navi Most implementations of getaddrinfo() use negative values for EAI_* codes, so it's still possible to encode everything in one byte 😅 But yeah, in any case you need some kind of trick, and yours is smart as well.

    💬 0🔄 0⭐ 0