summaryrefslogtreecommitdiff
path: root/negated_errno.h
blob: 0e9e9a2eea732b6dae40e5cfb597db8267631e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
 * Copyright (c) 2017-2018 The strace developers.
 * All rights reserved.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#ifndef STRACE_NEGATED_ERRNO_H
# define STRACE_NEGATED_ERRNO_H

/*
 * Check the syscall return value register value for whether it is
 * a negated errno code indicating an error, or a success return value.
 */
static inline bool
is_negated_errno(kernel_ulong_t val)
{
	kernel_ulong_t max = -(kernel_long_t) MAX_ERRNO_VALUE;

# ifndef current_klongsize
	if (current_klongsize < sizeof(val)) {
		val = (uint32_t) val;
		max = (uint32_t) max;
	}
# endif /* !current_klongsize */

	return val >= max;
}

#endif /* !STRACE_NEGATED_ERRNO_H */