2
0

err_mark.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #define OSSL_FORCE_ERR_STATE
  10. #include <openssl/err.h>
  11. #include "err_local.h"
  12. int ERR_set_mark(void)
  13. {
  14. ERR_STATE *es;
  15. es = ossl_err_get_state_int();
  16. if (es == NULL)
  17. return 0;
  18. if (es->bottom == es->top)
  19. return 0;
  20. es->err_marks[es->top]++;
  21. return 1;
  22. }
  23. int ERR_pop_to_mark(void)
  24. {
  25. ERR_STATE *es;
  26. es = ossl_err_get_state_int();
  27. if (es == NULL)
  28. return 0;
  29. while (es->bottom != es->top
  30. && es->err_marks[es->top] == 0) {
  31. err_clear(es, es->top, 0);
  32. es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
  33. }
  34. if (es->bottom == es->top)
  35. return 0;
  36. es->err_marks[es->top]--;
  37. return 1;
  38. }
  39. int ERR_count_to_mark(void)
  40. {
  41. ERR_STATE *es;
  42. int count = 0, top;
  43. es = ossl_err_get_state_int();
  44. if (es == NULL)
  45. return 0;
  46. top = es->top;
  47. while (es->bottom != top
  48. && es->err_marks[top] == 0) {
  49. ++count;
  50. top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1;
  51. }
  52. return count;
  53. }
  54. int ERR_clear_last_mark(void)
  55. {
  56. ERR_STATE *es;
  57. int top;
  58. es = ossl_err_get_state_int();
  59. if (es == NULL)
  60. return 0;
  61. top = es->top;
  62. while (es->bottom != top
  63. && es->err_marks[top] == 0) {
  64. top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1;
  65. }
  66. if (es->bottom == top)
  67. return 0;
  68. es->err_marks[top]--;
  69. return 1;
  70. }