1 // Copyright 2014 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.
5 #ifndef COMPONENTS_NACL_LOADER_NONSFI_IRT_UTIL_H_
6 #define COMPONENTS_NACL_LOADER_NONSFI_IRT_UTIL_H_
13 // For IRT implementation, the following simple pattern is commonly used.
15 // if (syscall(...) < 0)
19 // This function is a utility to write it in a line as follows:
21 // return CheckError(syscall(...));
22 inline int CheckError(int result
) {
23 return result
< 0 ? errno
: 0;
26 // For IRT implementation, another but a similar pattern is also commonly used.
28 // T result = syscall(...);
34 // This function is a utility to write it in a line as follows:
36 // retrun CheckErrorWithResult(syscall(...), output);
38 // Here, T1 must be a signed integer value, and T2 must be convertible from
40 template<typename T1
, typename T2
>
41 int CheckErrorWithResult(const T1
& result
, T2
* out
) {
52 #endif // COMPONENTS_NACL_LOADER_NONSFI_IRT_UTIL_H_