ERR_PUT_ERROR(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… ERR_PUT_ERROR(3) β€” like, the OpenSSL error-recording girlie

okay so bestie, gather round, because this one's from the Library Functions Manual and it's all about how OpenSSL writes down its little oopsies ✨


✨ NAME ✨

ERR_put_error β€” record an OpenSSL error πŸŽ€ (yes that's literally it, that's the whole job)


🌸 SYNOPSIS 🌸

first up, you gotta be linked against the library β€œlibcrypto” and pull in the header like so:

#include <openssl/err.h>

and then the function herself, in all her glory:

void
ERR_put_error(int lib, int func, int reason, const char *file,
    int line);

πŸ¦‹ DESCRIPTION πŸ¦‹

so ERR_put_error() adds an error code to the thread's error queue β€” like dropping a little note in the group chat that says "hey, something went sideways" πŸ’€

what it's signaling is: the error with reason code reason happened in function func, of library lib, on line number line of file. that's the whole vibe check β€” lib, func, reason, file, line, boom, recorded πŸ“

ngl, this function is usually called by a macro, not by you directly. you're not really supposed to be hand-writing these calls, bestie.

ERR_load_strings(3) is your girl for registering error strings, so your application can actually generate human-readable error messages for the error code. because raw codes are giving cryptic, and readable strings are giving iconic 🫢


πŸ’œ the XXXerr(f, r) macro situation

okay so every sub-library has its own specific macro, XXXerr(f, r), and it's the one used to report errors. here's the breakdown:

  • first argument β†’ a function code, XXX_F_*
  • second argument β†’ a reason code, XXX_R_*

function codes are derived from the function names, whereas reason codes consist of textual error descriptions. cute, right? πŸŽ€

for example, the function ssl23_read() reports a "handshake failure" like this:

SSLerr(SSL_F_SSL23_READ, SSL_R_SSL_HANDSHAKE_FAILURE);

slay. that's it. that's the whole report πŸ”₯


🧚 the naming rules (yes there are rules)

function and reason codes should consist of upper case characters, numbers and underscores only. no cap, that's the format, don't fight it πŸ’…

the error file generation script translates function codes into function names by looking in the header files for an appropriate function name. and if none is found? it just uses the capitalized form β€” like "SSL23_READ" in the example above. lowkey clever 🌈

also! the trailing section of a reason code (the part after the "_R_") gets translated into lower case, and the underscores get changed to spaces. so it actually reads like english at the end. obsessed 😭


πŸ“ the cross-library cameo

although a library will normally report errors using its own specific XXXerr() macro, another library's macro can be used. plot twist!

this is normally only done when a library wants to include ASN.1 code, which must use the ASN1err() macro. that's the one exception, iykyk 🐝

πŸ‘‘ SEE ALSO πŸ‘‘

go read those next, bestie, they're the supporting cast πŸ’–


⭐ HISTORY ⭐

ERR_put_error() first appeared in SSLeay 0.4.4 and has been available since OpenBSD 2.4. she's been booked and busy for literal decades, main character energy fr fr πŸ‘‘


and that's the page!! this cutie came to you from Debian, dated June 8, 2025 β€” mwah, go forth and record your errors responsibly πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from