handle_eintr.h 955 B

1234567891011121314151617181920
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef IPCZ_INCLUDE_SRC_REFERENCE_DRIVERS_HANDLE_EINTR_H_
  5. #define IPCZ_INCLUDE_SRC_REFERENCE_DRIVERS_HANDLE_EINTR_H_
  6. // Helper to ignore EINTR errors when making interruptible system calls. The
  7. // expression `x` is retried until it produces a non-error result or a non-EINTR
  8. // error.
  9. #define HANDLE_EINTR(x) \
  10. ({ \
  11. decltype(x) eintr_wrapper_result; \
  12. do { \
  13. eintr_wrapper_result = (x); \
  14. } while (eintr_wrapper_result == -1 && errno == EINTR); \
  15. eintr_wrapper_result; \
  16. })
  17. #endif // IPCZ_INCLUDE_SRC_REFERENCE_DRIVERS_HANDLE_EINTR_H_