2
0

err_mark.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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(void)
  24. {
  25. ERR_STATE *es;
  26. es = ossl_err_get_state_int();
  27. if (es == NULL || es->bottom == es->top)
  28. return 0;
  29. err_clear(es, es->top, 0);
  30. es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
  31. return 1;
  32. }
  33. int ERR_pop_to_mark(void)
  34. {
  35. ERR_STATE *es;
  36. es = ossl_err_get_state_int();
  37. if (es == NULL)
  38. return 0;
  39. while (es->bottom != es->top
  40. && es->err_marks[es->top] == 0) {
  41. err_clear(es, es->top, 0);
  42. es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
  43. }
  44. if (es->bottom == es->top)
  45. return 0;
  46. es->err_marks[es->top]--;
  47. return 1;
  48. }
  49. int ERR_count_to_mark(void)
  50. {
  51. ERR_STATE *es;
  52. int count = 0, top;
  53. es = ossl_err_get_state_int();
  54. if (es == NULL)
  55. return 0;
  56. top = es->top;
  57. while (es->bottom != top
  58. && es->err_marks[top] == 0) {
  59. ++count;
  60. top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1;
  61. }
  62. return count;
  63. }
  64. int ERR_clear_last_mark(void)
  65. {
  66. ERR_STATE *es;
  67. int top;
  68. es = ossl_err_get_state_int();
  69. if (es == NULL)
  70. return 0;
  71. top = es->top;
  72. while (es->bottom != top
  73. && es->err_marks[top] == 0) {
  74. top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1;
  75. }
  76. if (es->bottom == top)
  77. return 0;
  78. es->err_marks[top]--;
  79. return 1;
  80. }