aboutsummaryrefslogtreecommitdiffstats
path: root/abs.c
blob: feac9a70c6a1938b1a5979a2d91e72775a3ce9cf (plain) (blame)
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
/* See LICENSE file for copyright and license details. */
#include "internal.h"


void
liberror_abs_failed(int i)
{
	liberror_set_error_errno("The absolute value of largest negative integer "
	                         "cannot be represented as a signed integer",
	                         "abs", EOVERFLOW);
	(void) i;
}


int
liberror_abs(int i)
{
#if INT_MIN == -INT_MAX
	return abs(i);
#else
	if (i != INT_MIN)
		return abs(i);
	liberror_save_backtrace(NULL);
	liberror_abs_failed(i);
	return i;
#endif
}