err_mark.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright 2003-2022 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_clear_last_mark(void)
  40. {
  41. ERR_STATE *es;
  42. int 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. top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1;
  50. }
  51. if (es->bottom == top)
  52. return 0;
  53. es->err_marks[top]--;
  54. return 1;
  55. }