1 /* Utility for handling interrupted syscalls by signals.
3 Copyright (C) 2020-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef GDBSUPPORT_EINTR_H
21 #define GDBSUPPORT_EINTR_H
27 /* Repeat a system call interrupted with a signal.
29 A utility for handling interrupted syscalls, which return with error
30 and set the errno to EINTR. The interrupted syscalls can be repeated,
31 until successful completion. This utility avoids wrapping code with
32 manual checks for such errors which are highly repetitive.
40 ret = ::write (pipe[1], "+", 1);
42 while (ret == -1 && errno == EINTR);
44 You could wrap it by writing the wrapped form:
46 ssize_t ret = gdb::handle_eintr (-1, ::write, pipe[1], "+", 1);
48 ERRVAL specifies the failure value indicating that the call to the
49 F function with ARGS... arguments was possibly interrupted with a
52 template<typename ErrorValType
, typename Fun
, typename
... Args
>
54 handle_eintr (ErrorValType errval
, const Fun
&f
, const Args
&... args
)
55 -> decltype (f (args
...))
57 decltype (f (args
...)) ret
;
64 while (ret
== errval
&& errno
== EINTR
);
71 #endif /* GDBSUPPORT_EINTR_H */