xref: /aosp_15_r20/external/libchrome-gestures/include/eintr_wrapper.h (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1 // Copyright 2014 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // This provides a wrapper around system calls which may be interrupted by a
6 // signal and return EINTR. See man 7 signal.
7 
8 #ifndef GESTURES_EINTR_WRAPPER_H_
9 #define GESTURES_EINTR_WRAPPER_H_
10 
11 #include <errno.h>
12 
13 #define HANDLE_EINTR(x) ({ \
14   decltype(x) eintr_wrapper_result; \
15   do { \
16     eintr_wrapper_result = (x); \
17   } while (eintr_wrapper_result == -1 && errno == EINTR); \
18   eintr_wrapper_result; \
19 })
20 
21 #define IGNORE_EINTR(x) ({ \
22   decltype(x) eintr_wrapper_result; \
23   do { \
24     eintr_wrapper_result = (x); \
25     if (eintr_wrapper_result == -1 && errno == EINTR) { \
26       eintr_wrapper_result = 0; \
27     } \
28   } while (0); \
29   eintr_wrapper_result; \
30 })
31 
32 #endif  // GESTURES_EINTR_WRAPPER_H_
33