OSSL_ERR_STATE_SAVE(3ossl)

πŸ’– OSSL_ERR_STATE_SAVE β€” saving and restoring error state πŸ’–

okay bestie, so this is the OpenSSL page for OSSL_ERR_STATE_SAVE(3ossl) and it's literally all about ✨saving and restoring your error state✨ like it's a video game checkpoint. no cap.


✨ NAME ✨

OSSL_ERR_STATE_new, OSSL_ERR_STATE_save, OSSL_ERR_STATE_save_to_mark, OSSL_ERR_STATE_restore, OSSL_ERR_STATE_free β€” saving and restoring error state πŸŽ€


🌸 SYNOPSIS 🌸

#include <openssl/err.h>

ERR_STATE *OSSL_ERR_STATE_new(void);
void OSSL_ERR_STATE_save(ERR_STATE *es);
void OSSL_ERR_STATE_save_to_mark(ERR_STATE *es);
void OSSL_ERR_STATE_restore(const ERR_STATE *es);
void OSSL_ERR_STATE_free(ERR_STATE *es);

πŸ’… DESCRIPTION πŸ’…

so the whole vibe here is: these functions save and restore the error state from the thread local error state into a preallocated error state structure. it's giving snapshot and rollback, bestie. πŸ“Έ

  • OSSL_ERR_STATE_new() β€” allocates an empty error state structure, which you then use when saving and restoring thread error state. fresh start energy πŸ¦‹
  • OSSL_ERR_STATE_save() β€” saves the thread error state into es. and then? it clears the thread error state. gone. bye. πŸ’€ also, whatever was previously saved in es gets cleared before the new state is saved, so no stale leftovers, we don't do that here.
  • OSSL_ERR_STATE_save_to_mark() β€” similar to OSSL_ERR_STATE_save() but with a little twist ✨ it only saves ERR entries up to the most recent mark on the ERR stack. those entries get moved to es and removed from the thread error state. BUT (and this is the important part, don't skip it πŸ™ˆ) the most recent marked ERR and any ERR state before it stays part of the thread error state and does not get moved to the ERR_STATE. the mark is not cleared, and it must be cleared explicitly after a call to this function, using ERR_pop_to_mark(3) or ERR_clear_last_mark(3). and since a call to OSSL_ERR_STATE_save_to_mark() leaves the marked ERR as the top error, either of those functions will have the same effect. iykyk. and if there's no marked ERR in the thread local error state? then all ERR entries are copied and the effect is the same as a call to OSSL_ERR_STATE_save(). easy.
  • OSSL_ERR_STATE_restore() β€” adds all the error entries from the saved state es to the thread error state. existing entries in the thread error state are not affected if there's enough space for all the added entries. and any allocated data in the saved error entries gets duplicated when adding to the thread state. copy-paste but make it official 🫢
  • OSSL_ERR_STATE_free() β€” frees the saved error state es. and if the argument is NULL? nothing happens. no drama, no crash, we love a chill function. 😌

πŸ‘‘ RETURN VALUES πŸ‘‘

  • OSSL_ERR_STATE_new() returns a pointer to the allocated ERR_STATE structure, or NULL on error. 😭
  • OSSL_ERR_STATE_save(), OSSL_ERR_STATE_save_to_mark(), OSSL_ERR_STATE_restore(), and OSSL_ERR_STATE_free() do not return any values. they're void, they simply do the thing and leave. main character exit. πŸ’…

🧚 NOTES 🧚

  • OSSL_ERR_STATE_save() and OSSL_ERR_STATE_save_to_mark() cannot fail, because they take over any allocated data from the thread error state. slay, no failure mode. ✨
  • OSSL_ERR_STATE_restore() is a best effort function. the only failure that can happen during its operation is when memory allocation fails. and because it manipulates the thread error state, it avoids raising memory errors on such failure. at worst, the restored error entries will be missing the auxiliary error data. so like… mostly fine, slightly imperfect, relatable. πŸ™ˆ

🌈 SEE ALSO 🌈

ERR_raise(3), ERR_get_error(3), ERR_clear_error(3)


⭐ HISTORY ⭐

all of these functions were added in OpenSSL 3.2. so if you're on something older, this is not for you bestie, upgrade. πŸ’œ


Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page, periodt. πŸ’– this was OpenSSL 3.5.9, dated 2026-09-29, and it's the OSSL_ERR_STATE_SAVE(3ossl) manual. go forth and save your error state, queen. πŸ¦‹πŸ‘‘

πŸ“¦ where this page comes from