bootloader_util.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <stddef.h>
  16. /**
  17. * @brief Check if half-open intervals overlap
  18. *
  19. * @param start1 interval 1 start
  20. * @param end1 interval 1 end
  21. * @param start2 interval 2 start
  22. * @param end2 interval 2 end
  23. * @return true iff [start1; end1) overlaps [start2; end2)
  24. */
  25. static inline bool bootloader_util_regions_overlap(
  26. const intptr_t start1, const intptr_t end1,
  27. const intptr_t start2, const intptr_t end2)
  28. {
  29. return (end1 > start2 && end2 > start1) ||
  30. !(end1 <= start2 || end2 <= start1);
  31. }