OSSL_ERR_STATE_SAVE(3ossl)
π OSSL_ERR_STATE_SAVE β saving and restoring error state β¨
okay so bestie, this is the 3ossl manual page for the OpenSSL error-state save/restore girlies π. If you've ever wanted to scoop up your thread's error state, tuck it into a little preallocated ERR_STATE box, and put it back later β this is your moment. no cap. π«Ά
πΈ 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 β¨
These functions save and restore the error state, moving it from the thread local error state into a preallocated error state structure π. It's giving "pack up your emotional baggage and label it" energy. π§³
OSSL_ERR_STATE_new()β allocates an empty error state structure, so you have somewhere cute to put things when you're saving and restoring thread error state. πOSSL_ERR_STATE_save()β saves the thread error state intoes. Then it clears the thread error state, like, immediately. Any state that was previously saved inesgets cleared first, before the new state goes in. out with the old, in with the new, periodt. πOSSL_ERR_STATE_save_to_mark()β same vibe asOSSL_ERR_STATE_save(), except it only savesERRentries up to the most recent mark on theERRstack β¨. Those entries get moved toesand removed from the thread error state. BUT β and this is the plot twist π β the most recent markedERR, plus anyERRstate before it, stays part of the thread error state. it does not get moved to theERR_STATE. And the mark is not cleared! you have to clear it explicitly after calling this function, usingERR_pop_to_mark(3)orERR_clear_last_mark(3). and here's the fun part: since a call toOSSL_ERR_STATE_save_to_mark()leaves the markedERRas the top error, either of those functions will have the exact same effect. iykyk. π¦
also, if there's no markedERRin the thread local error state, allERRentries are copied and the effect is the same as a call toOSSL_ERR_STATE_save(). so, like, no drama either way. π
OSSL_ERR_STATE_restore()β adds all the error entries from the saved stateesback into the thread error state π. Existing entries in the thread error state are not affected, as long as there's enough space for all the added entries. Any allocated data in the saved error entries gets duplicated when it's added to the thread state. bespoke copies, no sharing. πOSSL_ERR_STATE_free()β frees the saved error stateesπ. If the argument isNULL, nothing happens. iconic minimalism, honestly. β¨
π RETURN VALUES π
OSSL_ERR_STATE_new()returns a pointer to the allocatedERR_STATEstructure, orNULLon error π.OSSL_ERR_STATE_save(),OSSL_ERR_STATE_save_to_mark(),OSSL_ERR_STATE_restore(), andOSSL_ERR_STATE_free()do not return any values. they simply are. π
π¦ 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. so, like, no failure arc here. β
OSSL_ERR_STATE_restore() is a best effort function π«Ά. The only failure that can happen during its operation is when memory allocation fails. 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. not the end of the world, bestie. π
π SEE ALSO π
ERR_raise(3), ERR_get_error(3), ERR_clear_error(3)
π HISTORY π
All of these functions were added in OpenSSL 3.2 β¨. they're new-ish, they're fresh, they ate. π₯
π COPYRIGHT π
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>.
mwah π this page is from OpenSSL 3.5.0, dated 2026-09-25. go save your error state, bestie β OSSL_ERR_STATE_SAVE(3ossl) out. πΈπ
β¨
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms