1 /* 2 * Copyright 2003-2023 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the Apache License 2.0 (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10 #define OSSL_FORCE_ERR_STATE 11 12 #include <openssl/err.h> 13 #include "err_local.h" 14 ERR_set_mark(void)15int ERR_set_mark(void) 16 { 17 ERR_STATE *es; 18 19 es = ossl_err_get_state_int(); 20 if (es == NULL) 21 return 0; 22 23 if (es->bottom == es->top) 24 return 0; 25 es->err_marks[es->top]++; 26 return 1; 27 } 28 ERR_pop(void)29int ERR_pop(void) 30 { 31 ERR_STATE *es; 32 33 es = ossl_err_get_state_int(); 34 if (es == NULL || es->bottom == es->top) 35 return 0; 36 37 err_clear(es, es->top, 0); 38 es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1; 39 return 1; 40 } 41 ERR_pop_to_mark(void)42int ERR_pop_to_mark(void) 43 { 44 ERR_STATE *es; 45 46 es = ossl_err_get_state_int(); 47 if (es == NULL) 48 return 0; 49 50 while (es->bottom != es->top 51 && es->err_marks[es->top] == 0) { 52 err_clear(es, es->top, 0); 53 es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1; 54 } 55 56 if (es->bottom == es->top) 57 return 0; 58 es->err_marks[es->top]--; 59 return 1; 60 } 61 ERR_count_to_mark(void)62int ERR_count_to_mark(void) 63 { 64 ERR_STATE *es; 65 int count = 0, top; 66 67 es = ossl_err_get_state_int(); 68 if (es == NULL) 69 return 0; 70 71 top = es->top; 72 while (es->bottom != top 73 && es->err_marks[top] == 0) { 74 ++count; 75 top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1; 76 } 77 78 return count; 79 } 80 ERR_clear_last_mark(void)81int ERR_clear_last_mark(void) 82 { 83 ERR_STATE *es; 84 int top; 85 86 es = ossl_err_get_state_int(); 87 if (es == NULL) 88 return 0; 89 90 top = es->top; 91 while (es->bottom != top 92 && es->err_marks[top] == 0) { 93 top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1; 94 } 95 96 if (es->bottom == top) 97 return 0; 98 es->err_marks[top]--; 99 return 1; 100 } 101 102